Browse Source

Try TypeConverters in TryConvert.

Fixes #3584.
pull/3585/head
Steven Kirk 6 years ago
parent
commit
de2b1925d9
  1. 9
      src/Avalonia.Base/Utilities/TypeUtilities.cs

9
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)

Loading…
Cancel
Save