From 9612664387467f311e887c7ab7e69286d35323ae Mon Sep 17 00:00:00 2001 From: David Hall Date: Thu, 7 Mar 2019 09:22:40 -0700 Subject: [PATCH] Fixed Write methods to better handle string types --- Core/InteropServices/MarshalingStream.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Core/InteropServices/MarshalingStream.cs b/Core/InteropServices/MarshalingStream.cs index 32ce1f29..5ed5cc68 100644 --- a/Core/InteropServices/MarshalingStream.cs +++ b/Core/InteropServices/MarshalingStream.cs @@ -137,9 +137,9 @@ namespace Vanara.InteropServices public void Write(T value) { if (value == null) return; - if (typeof(T) == typeof(string)) + if (value is string s) { - var bytes = value.ToString().GetBytes(true, CharSet); + var bytes = s.GetBytes(true, CharSet); Write(bytes, 0, bytes.Length); } else @@ -157,7 +157,7 @@ namespace Vanara.InteropServices public void Write(T[] items) { if (items == null) return; - if (typeof(T) == typeof(string)) + if (items.GetType().GetElementType() == typeof(string)) { var hMem = SafeHGlobalHandle.CreateFromStringList(items as string[], StringListPackMethod.Packed, CharSet, 0); var bytes = hMem.ToArray(hMem.Size);