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:
parent
1c05905058
commit
afa98e40b6
1 changed files with 24 additions and 0 deletions
|
@ -131,6 +131,11 @@ namespace System.Reflection
|
||||||
|
|
||||||
var (objType, dataPtr) = GetTypeAndPointer(obj);
|
var (objType, dataPtr) = GetTypeAndPointer(obj);
|
||||||
|
|
||||||
|
if (objType == type)
|
||||||
|
{
|
||||||
|
return Variant.Create(type, dataPtr);
|
||||||
|
}
|
||||||
|
|
||||||
if (objType.IsPrimitive)
|
if (objType.IsPrimitive)
|
||||||
{
|
{
|
||||||
if (objType.IsInteger)
|
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;
|
return .Err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue