1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-15 14:54:09 +02:00

Improved reflection method invocation argument handling

This commit is contained in:
Brian Fiete 2022-03-01 11:12:07 -08:00
parent fa3b69e0c7
commit bc46807003
3 changed files with 15 additions and 6 deletions

View file

@ -108,6 +108,8 @@ namespace System.Reflection
if (methodInfo.Invoke(targetAttr, params args) case .Ok(var val)) if (methodInfo.Invoke(targetAttr, params args) case .Ok(var val))
val.Dispose(); val.Dispose();
else
return .Err;
return .Ok; return .Ok;
} }

View file

@ -138,6 +138,9 @@ namespace System.Reflection
int64 intVal = ToInt64(obj); int64 intVal = ToInt64(obj);
switch (type.[Friend]mTypeCode) switch (type.[Friend]mTypeCode)
{ {
case .Boolean:
bool val = intVal != 0;
return Variant.Create(type, &val);
case .Float: case .Float:
float val = (.)intVal; float val = (.)intVal;
return Variant.Create(type, &val); return Variant.Create(type, &val);

View file

@ -671,25 +671,29 @@ namespace System.Reflection
} }
else if (paramType.IsValueType) else if (paramType.IsValueType)
{ {
handled = true;
if (!argType.IsBoxed) if (!argType.IsBoxed)
return .Err(.InvalidArgument((.)argIdx)); return .Err(.InvalidArgument((.)argIdx));
Type underlyingType = argType.UnderlyingType; Type underlyingType = argType.UnderlyingType;
if (underlyingType == paramType)
handled = true;
if ((paramType.IsPrimitive) && (underlyingType.IsTypedPrimitive)) // Boxed primitive? if ((paramType.IsPrimitive) && (underlyingType.IsTypedPrimitive)) // Boxed primitive?
underlyingType = underlyingType.UnderlyingType; underlyingType = underlyingType.UnderlyingType;
if (argType.IsBoxedStructPtr || argType.IsBoxedPrimitivePtr) if ((paramType.IsTypedPrimitive) && (underlyingType.IsTypedPrimitive) &&
(paramType.UnderlyingType == underlyingType.UnderlyingType))
{ {
dataPtr = *(void**)dataPtr;
handled = true; handled = true;
} }
else else if (argType.IsBoxedStructPtr || argType.IsBoxedPrimitivePtr)
{ {
isValid = underlyingType == paramType; dataPtr = *(void**)dataPtr;
} }
if (underlyingType == paramType)
handled = true;
if (!handled) if (!handled)
{ {
if (!underlyingType.IsSubtypeOf(paramType)) if (!underlyingType.IsSubtypeOf(paramType))