More improvement to test GetStringVal helper

pull/211/head
dahall 2021-01-14 11:16:01 -07:00
parent c5c0833b98
commit a15b408561
1 changed files with 25 additions and 10 deletions

View File

@ -65,20 +65,35 @@ namespace Vanara.PInvoke.Tests
public static string GetStringVal(this object value)
{
if (value is null)
return "(null)";
else
switch (value)
{
if (value is System.Runtime.InteropServices.ComTypes.FILETIME ft)
value = ft.ToDateTime();
else if (value is SYSTEMTIME st)
value = st.ToDateTime(DateTimeKind.Local);
case null:
return "(null)";
if (value.GetType().IsPrimitive || value is DateTime || value is Decimal)
case System.Runtime.InteropServices.ComTypes.FILETIME ft:
value = ft.ToDateTime();
goto Simple;
case SYSTEMTIME st:
value = st.ToDateTime(DateTimeKind.Local);
goto Simple;
case DateTime:
case Decimal:
case var v when v.GetType().IsPrimitive:
Simple:
return $"{value.GetType().Name} : [{value}]";
if (value is string s)
case string s:
return string.Concat("\"", s, "\"");
else
case byte[] bytes:
return string.Join(" ", Array.ConvertAll(bytes, b => $"{b:X2}"));
case SafeAllocatedMemoryHandleBase mem:
return mem.Dump;
default:
return JsonConvert.SerializeObject(value, Formatting.Indented, new Newtonsoft.Json.Converters.StringEnumConverter(), new SizeTConverter());
}
}