Fixed Write methods to better handle string types

pull/60/head
David Hall 2019-03-07 09:22:40 -07:00
parent 0ede8d5738
commit 9612664387
1 changed files with 3 additions and 3 deletions

View File

@ -137,9 +137,9 @@ namespace Vanara.InteropServices
public void Write<T>(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>(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<byte>(hMem.Size);