mirror of
https://github.com/holgerb83/ModernWpfPlayground.git
synced 2025-06-30 09:40:52 +02:00
switched to yaml as filee format
This commit is contained in:
20
MvvmStuff/DeserializationExtension.cs
Normal file
20
MvvmStuff/DeserializationExtension.cs
Normal file
@ -0,0 +1,20 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user