From 38bc2953d6d88193080e519fe05532c950f50dd7 Mon Sep 17 00:00:00 2001 From: Harald Wolff Date: Mon, 7 Dec 2020 09:04:42 +0100 Subject: [PATCH] Added TypeDescriptor.GetConverter().ConvertFromInvariantString(..) to Cast.To(..) --- Cast.cs | 5 +++++ ln.type.csproj | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Cast.cs b/Cast.cs index 6090ef6..fc09d25 100644 --- a/Cast.cs +++ b/Cast.cs @@ -12,6 +12,7 @@ using System.Reflection; using System.Linq; using System.Threading; using System.Net.Http.Headers; +using System.ComponentModel; namespace ln.type { @@ -68,6 +69,10 @@ namespace ln.type targetValue = castedArray; } + else if ((value is string text) && (TypeDescriptor.GetConverter(targetType).CanConvertFrom(typeof(string)))) + { + targetValue = TypeDescriptor.GetConverter(targetType).ConvertFromInvariantString(value as string); + } else { targetValue = Convert.ChangeType(value, targetType); diff --git a/ln.type.csproj b/ln.type.csproj index 2a7a30e..35c8e1c 100644 --- a/ln.type.csproj +++ b/ln.type.csproj @@ -3,7 +3,7 @@ netcoreapp3.1 true - 0.1.3 + 0.1.4 Harald Wolff-Thobaben l--n.de 0.0.1.0