Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/xamarin/Xamarin.PropertyEditing.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Maupin <me@ermau.com>2018-07-03 01:04:57 +0300
committerGitHub <noreply@github.com>2018-07-03 01:04:57 +0300
commit10295228d19116f5930ad81ea11a87d1d7ec0f40 (patch)
tree781a3ebace623ab835758997651661d07b08a2b4 /Xamarin.PropertyEditing.Tests
parent297ff122741cab1860164c5ab15f476cc89868ef (diff)
parentf0d6d95a08a67d263cdffe65cf6cac67cb243be2 (diff)
Merge pull request #322 from xamarin/bleroy-color-properties
Allow for properties of type CommonColor.
Diffstat (limited to 'Xamarin.PropertyEditing.Tests')
-rw-r--r--Xamarin.PropertyEditing.Tests/MockObjectEditor.cs21
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,