mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-10 04:22:20 +02:00
Merge pull request #1492 from disarray2077/patch-10
Fix `CustomAttributeEnumerator`
This commit is contained in:
commit
fea7ba67f8
2 changed files with 30 additions and 10 deletions
|
@ -157,7 +157,7 @@ namespace System.Reflection
|
||||||
TypeInstance attrTypeInst = attrType as TypeInstance;
|
TypeInstance attrTypeInst = attrType as TypeInstance;
|
||||||
MethodInfo methodInfo = .(attrTypeInst, attrTypeInst.[Friend]mMethodDataPtr + methodIdx);
|
MethodInfo methodInfo = .(attrTypeInst, attrTypeInst.[Friend]mMethodDataPtr + methodIdx);
|
||||||
|
|
||||||
Object[] args = scope Object[methodInfo.[Friend]mData.mMethodData.mParamCount];
|
Variant[] args = scope Variant[methodInfo.[Friend]mData.mMethodData.mParamCount];
|
||||||
|
|
||||||
int argIdx = 0;
|
int argIdx = 0;
|
||||||
while (mData < endPtr)
|
while (mData < endPtr)
|
||||||
|
@ -170,32 +170,32 @@ namespace System.Reflection
|
||||||
.Char8,
|
.Char8,
|
||||||
.Boolean:
|
.Boolean:
|
||||||
let attrData = AttributeInfo.Decode!<int8>(mData);
|
let attrData = AttributeInfo.Decode!<int8>(mData);
|
||||||
args[argIdx] = scope:: box attrData;
|
args[argIdx] = Variant.Create(attrData);
|
||||||
case .Int16,
|
case .Int16,
|
||||||
.UInt16,
|
.UInt16,
|
||||||
.Char16:
|
.Char16:
|
||||||
let attrData = AttributeInfo.Decode!<int16>(mData);
|
let attrData = AttributeInfo.Decode!<int16>(mData);
|
||||||
args[argIdx] = scope:: box attrData;
|
args[argIdx] = Variant.Create(attrData);
|
||||||
case .Int32,
|
case .Int32,
|
||||||
.UInt32,
|
.UInt32,
|
||||||
.Char32:
|
.Char32:
|
||||||
let attrData = AttributeInfo.Decode!<int32>(mData);
|
let attrData = AttributeInfo.Decode!<int32>(mData);
|
||||||
args[argIdx] = scope:: box attrData;
|
args[argIdx] = Variant.Create(attrData);
|
||||||
case .Float:
|
case .Float:
|
||||||
let attrData = AttributeInfo.Decode!<float>(mData);
|
let attrData = AttributeInfo.Decode!<float>(mData);
|
||||||
args[argIdx] = scope:: box attrData;
|
args[argIdx] = Variant.Create(attrData);
|
||||||
case .Int64,
|
case .Int64,
|
||||||
.UInt64,
|
.UInt64,
|
||||||
.Double:
|
.Double:
|
||||||
let attrData = AttributeInfo.Decode!<int64>(mData);
|
let attrData = AttributeInfo.Decode!<int64>(mData);
|
||||||
args[argIdx] = scope:: box attrData;
|
args[argIdx] = Variant.Create(attrData);
|
||||||
case (TypeCode)typeof(TypeCode).MaxValue + 8: //BfConstType_TypeOf
|
case (TypeCode)typeof(TypeCode).MaxValue + 8: //BfConstType_TypeOf
|
||||||
let argTypeId = AttributeInfo.Decode!<int32>(mData);
|
let argTypeId = AttributeInfo.Decode!<int32>(mData);
|
||||||
args[argIdx] = Type.[Friend]GetType((.)argTypeId);
|
args[argIdx] = Variant.Create(Type.[Friend]GetType((.)argTypeId));
|
||||||
case (TypeCode)255:
|
case (TypeCode)255:
|
||||||
let stringId = AttributeInfo.Decode!<int32>(mData);
|
let stringId = AttributeInfo.Decode!<int32>(mData);
|
||||||
String str = String.[Friend]sIdStringLiterals[stringId];
|
String str = String.[Friend]sIdStringLiterals[stringId];
|
||||||
args[argIdx] = str;
|
args[argIdx] = Variant.Create(str);
|
||||||
default:
|
default:
|
||||||
Runtime.FatalError("Not handled");
|
Runtime.FatalError("Not handled");
|
||||||
}
|
}
|
||||||
|
@ -203,10 +203,13 @@ namespace System.Reflection
|
||||||
}
|
}
|
||||||
|
|
||||||
mTargetAttr.Dispose();
|
mTargetAttr.Dispose();
|
||||||
void* data = Variant.Alloc(attrType, out mTargetAttr);
|
Variant.AllocOwned(attrType, out mTargetAttr);
|
||||||
|
|
||||||
if (methodInfo.Invoke(data, params args) case .Ok(var val))
|
if (methodInfo.Invoke(mTargetAttr, params args) case .Ok(var val))
|
||||||
val.Dispose();
|
val.Dispose();
|
||||||
|
|
||||||
|
for (var variant in ref args)
|
||||||
|
variant.Dispose();
|
||||||
|
|
||||||
mAttrIdx++;
|
mAttrIdx++;
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -265,6 +265,23 @@ namespace System
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void* AllocOwned(Type type, out Variant variant)
|
||||||
|
{
|
||||||
|
variant = .();
|
||||||
|
|
||||||
|
if (type.IsObject)
|
||||||
|
{
|
||||||
|
return &variant.mData;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
variant.mStructType = (int)Internal.UnsafeCastToPtr(type) | 1;
|
||||||
|
void* data = new uint8[type.[Friend]mSize]*;
|
||||||
|
variant.mData = (int)data;
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public T Get<T>() where T : class
|
public T Get<T>() where T : class
|
||||||
{
|
{
|
||||||
Debug.Assert(IsObject);
|
Debug.Assert(IsObject);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue