From c83bec6e81421553741d39d4966b9d3ee8d09e22 Mon Sep 17 00:00:00 2001 From: PMExtra Date: Fri, 3 Apr 2020 14:44:04 +0800 Subject: [PATCH] Fix for Nullable. --- Source/MQTTnet/Extensions/UserPropertyExtension.cs | 4 +++- Source/MQTTnet/MQTTnet.csproj | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Source/MQTTnet/Extensions/UserPropertyExtension.cs b/Source/MQTTnet/Extensions/UserPropertyExtension.cs index 8918600..e950141 100644 --- a/Source/MQTTnet/Extensions/UserPropertyExtension.cs +++ b/Source/MQTTnet/Extensions/UserPropertyExtension.cs @@ -1,4 +1,5 @@ using System; +using System.ComponentModel; using System.Linq; namespace MQTTnet.Extensions @@ -17,9 +18,10 @@ namespace MQTTnet.Extensions { var value = GetUserProperty(message, propertyName, comparisonType); + var typeDescriptor = TypeDescriptor.GetConverter(typeof(T)); try { - return (T) Convert.ChangeType(value, typeof(T)); + return (T) typeDescriptor.ConvertFromString(value); } catch (Exception ex) { diff --git a/Source/MQTTnet/MQTTnet.csproj b/Source/MQTTnet/MQTTnet.csproj index 28e3f3d..07b9161 100644 --- a/Source/MQTTnet/MQTTnet.csproj +++ b/Source/MQTTnet/MQTTnet.csproj @@ -42,6 +42,7 @@ +