Przeglądaj źródła

Try TypeConverters in TryConvert.

Fixes #3584.
Steven Kirk 5 lat temu
rodzic
commit
de2b1925d9
1 zmienionych plików z 9 dodań i 0 usunięć
  1. 9 0
      src/Avalonia.Base/Utilities/TypeUtilities.cs

+ 9 - 0
src/Avalonia.Base/Utilities/TypeUtilities.cs

@@ -2,6 +2,7 @@
 // Licensed under the MIT license. See licence.md file in the project root for full license information.
 
 using System;
+using System.ComponentModel;
 using System.Globalization;
 using System.Linq;
 using System.Reflection;
@@ -185,6 +186,14 @@ namespace Avalonia.Utilities
                 }
             }
 
+            var typeConverter = TypeDescriptor.GetConverter(to);
+
+            if (typeConverter.CanConvertFrom(from) == true)
+            {
+                result = typeConverter.ConvertFrom(null, culture, value);
+                return true;
+            }
+
             var cast = FindTypeConversionOperatorMethod(from, to, OperatorType.Implicit | OperatorType.Explicit);
 
             if (cast != null)