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 <ermaup@microsoft.com>2018-09-28 21:00:21 +0300
committerEric Maupin <ermaup@microsoft.com>2018-09-28 21:31:13 +0300
commit46c79646e2cbf01526305628f6d83f37fe5a1627 (patch)
treeff1ac7458029946fc6b78e82f2633fea2aa7728e /Xamarin.PropertyEditing.Tests
parent770449b1c6253585a4e8237c43f9011da5b42a09 (diff)
[Tests] Better converter from nullable to normal #
Diffstat (limited to 'Xamarin.PropertyEditing.Tests')
-rw-r--r--Xamarin.PropertyEditing.Tests/MockObjectEditor.cs17
1 files changed, 14 insertions, 3 deletions
diff --git a/Xamarin.PropertyEditing.Tests/MockObjectEditor.cs b/Xamarin.PropertyEditing.Tests/MockObjectEditor.cs
index 3adb37e..58e7932 100644
--- a/Xamarin.PropertyEditing.Tests/MockObjectEditor.cs
+++ b/Xamarin.PropertyEditing.Tests/MockObjectEditor.cs
@@ -187,9 +187,20 @@ namespace Xamarin.PropertyEditing.Tests
if (typeof(T) != property.Type) {
IPropertyConverter converter = property as IPropertyConverter;
- object v;
- if (converter != null && converter.TryConvert (value.Value, property.Type, out v)) {
- var softType = typeof(ValueInfo<>).MakeGenericType (property.Type);
+ bool changeValueInfo = false;
+
+ object v = value.Value;
+ if (ReferenceEquals (value.Value, null) && property.Type.IsValueType) {
+ if ((property.ValueSources & ValueSources.Default) == ValueSources.Default) {
+ v = Activator.CreateInstance (property.Type);
+ changeValueInfo = true;
+ }
+ } else if (converter != null && converter.TryConvert (value.Value, property.Type, out v)) {
+ changeValueInfo = true;
+ }
+
+ if (changeValueInfo) {
+ var softType = typeof (ValueInfo<>).MakeGenericType (property.Type);
softValue = Activator.CreateInstance (softType);
softType.GetProperty ("Value").SetValue (softValue, v);
softType.GetProperty ("ValueDescriptor").SetValue (softValue, value.ValueDescriptor);