1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-09 03:52:19 +02:00

Fix conversion from primitives to nullables

This commit is contained in:
Brian Fiete 2022-03-02 09:09:06 -08:00
parent 1c05905058
commit afa98e40b6

View file

@ -131,6 +131,11 @@ namespace System.Reflection
var (objType, dataPtr) = GetTypeAndPointer(obj);
if (objType == type)
{
return Variant.Create(type, dataPtr);
}
if (objType.IsPrimitive)
{
if (objType.IsInteger)
@ -166,6 +171,25 @@ namespace System.Reflection
}
}
if (var unspecializedType = type as SpecializedGenericType)
{
if (unspecializedType.UnspecializedType == typeof(Nullable<>))
{
switch (ConvertTo(obj, unspecializedType.GetGenericArg(0)))
{
case .Ok(var ref val):
Variant.Alloc(type, var nullableVariant);
Internal.MemCpy(nullableVariant.DataPtr, val.DataPtr, val.VariantType.Size);
*((bool*)nullableVariant.DataPtr + val.VariantType.Size) = true;
return nullableVariant;
case .Err:
return .Err;
}
}
}
return .Err;
}
}