mirror of
https://github.com/holgerb83/ModernWpfPlayground.git
synced 2025-04-16 21:43:51 +02:00
20 lines
557 B
C#
20 lines
557 B
C#
using System;
|
|
using System.Globalization;
|
|
|
|
namespace ModernWpfPlayground.MvvmStuff
|
|
{
|
|
public static class DeserializationExtension
|
|
{
|
|
public static object? Convert(object? value, Type propertyType)
|
|
{
|
|
if (value is null) return Activator.CreateInstance(propertyType);
|
|
|
|
if (propertyType.IsEnum && value is string s)
|
|
{
|
|
return Enum.Parse(propertyType, s);
|
|
}
|
|
|
|
return System.Convert.ChangeType(value, propertyType, CultureInfo.InvariantCulture);
|
|
}
|
|
}
|
|
} |