diff options
author | Bertrand Le Roy <beleroy@microsoft.com> | 2018-06-12 05:47:09 +0300 |
---|---|---|
committer | Bertrand Le Roy <beleroy@microsoft.com> | 2018-06-20 21:23:50 +0300 |
commit | f0d6d95a08a67d263cdffe65cf6cac67cb243be2 (patch) | |
tree | f41b5a0e18e8614facd224f3a9ed16cd44705c87 /Xamarin.PropertyEditing.Tests | |
parent | 0cec86376f629b4dfc682797557a70c591fc1a84 (diff) |
Allow for properties of type CommonColor.
Diffstat (limited to 'Xamarin.PropertyEditing.Tests')
-rw-r--r-- | Xamarin.PropertyEditing.Tests/MockObjectEditor.cs | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/Xamarin.PropertyEditing.Tests/MockObjectEditor.cs b/Xamarin.PropertyEditing.Tests/MockObjectEditor.cs index fdd59ae..8c0f6a5 100644 --- a/Xamarin.PropertyEditing.Tests/MockObjectEditor.cs +++ b/Xamarin.PropertyEditing.Tests/MockObjectEditor.cs @@ -1,6 +1,8 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; +using System.Reflection; using System.Threading.Tasks; using Xamarin.PropertyEditing.Reflection; using Xamarin.PropertyEditing.Tests.MockControls; @@ -188,10 +190,19 @@ namespace Xamarin.PropertyEditing.Tests // Set to resource won't pass values so we will store it on the info since we just pass it back in GetValue if (value.Source == ValueSource.Resource && value.ValueDescriptor is Resource) { - var rt = value.ValueDescriptor.GetType(); - if (rt.IsGenericType && typeof(T).IsAssignableFrom (rt.GetGenericArguments ()[0])) { - var pi = rt.GetProperty ("Value"); - value.Value = (T)pi.GetValue (value.ValueDescriptor); + Type rt = value.ValueDescriptor.GetType(); + if (rt.IsGenericType) { + Type ta = rt.GetGenericArguments ()[0]; + if (typeof (T).IsAssignableFrom (ta)) { + PropertyInfo pi = rt.GetProperty ("Value"); + value.Value = (T)pi.GetValue (value.ValueDescriptor); + } else { + TypeConverter converter = TypeDescriptor.GetConverter (ta); + if (converter != null && converter.CanConvertTo(typeof(T))) { + PropertyInfo pi = rt.GetProperty ("Value"); + value.Value = (T)converter.ConvertTo (pi.GetValue (value.ValueDescriptor), typeof (T)); + } + } } } @@ -259,7 +270,7 @@ namespace Xamarin.PropertyEditing.Tests object newValue; IPropertyConverter converter = property as IPropertyConverter; - if (converter != null && converter.TryConvert (value, typeof(T), out newValue)) { + if (converter != null && converter.TryConvert (value, tType, out newValue)) { return new ValueInfo<T> { Source = source, Value = (T)newValue, |