summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Core
diff options
context:
space:
mode:
authorSamantha Houts <samantha@teamredwall.com>2016-03-31 10:38:45 -0700
committerSamantha Houts <samantha@teamredwall.com>2016-03-31 10:38:45 -0700
commit850591679f51ed27cf00707296156ab4ed363873 (patch)
treeaee758221f272f6e09b5ac55b5c2dec63bd0db97 /Xamarin.Forms.Core
parentb3a64fadb3951d4e5e65b5f000a5f930772c01ed (diff)
parent99b27e9658425da98c6216cc1f804c42d3f43d6f (diff)
downloadxamarin-forms-850591679f51ed27cf00707296156ab4ed363873.tar.gz
xamarin-forms-850591679f51ed27cf00707296156ab4ed363873.tar.bz2
xamarin-forms-850591679f51ed27cf00707296156ab4ed363873.zip
Merge pull request #32 from xamarin/fix-bugzilla39378
[Controls,Core]Allow well known type conversions on the binding system
Diffstat (limited to 'Xamarin.Forms.Core')
-rw-r--r--Xamarin.Forms.Core/BindableProperty.cs11
1 files changed, 11 insertions, 0 deletions
diff --git a/Xamarin.Forms.Core/BindableProperty.cs b/Xamarin.Forms.Core/BindableProperty.cs
index f95d38ab..5eb330ff 100644
--- a/Xamarin.Forms.Core/BindableProperty.cs
+++ b/Xamarin.Forms.Core/BindableProperty.cs
@@ -30,6 +30,12 @@ namespace Xamarin.Forms
public delegate bool ValidateValueDelegate<in TPropertyType>(BindableObject bindable, TPropertyType value);
+ static readonly Dictionary<Type, TypeConverter> WellKnownConvertTypes = new Dictionary<Type,TypeConverter>
+ {
+ { typeof(Uri), new UriTypeConverter() },
+ { typeof(Color), new ColorTypeConverter() },
+ };
+
// more or less the encoding of this, without the need to reflect
// http://msdn.microsoft.com/en-us/library/y5b434w4.aspx
static readonly Dictionary<Type, Type[]> SimpleConvertTypes = new Dictionary<Type, Type[]>
@@ -303,10 +309,15 @@ namespace Xamarin.Forms
// Dont support arbitrary IConvertible by limiting which types can use this
Type[] convertableTo;
+ TypeConverter typeConverterTo;
if (SimpleConvertTypes.TryGetValue(valueType, out convertableTo) && Array.IndexOf(convertableTo, type) != -1)
{
value = Convert.ChangeType(value, type);
}
+ else if (WellKnownConvertTypes.TryGetValue(type, out typeConverterTo) && typeConverterTo.CanConvertFrom(valueType))
+ {
+ value = typeConverterTo.ConvertFromInvariantString(value.ToString());
+ }
else if (!ReturnTypeInfo.IsAssignableFrom(valueType.GetTypeInfo()))
{
// Is there an implicit cast operator ?