mirror of
https://github.com/beefytech/Beef.git
synced 2025-07-02 22:36:00 +02:00
Reflection support for methods and types
This commit is contained in:
parent
f1eafa8d81
commit
be6a132fb5
4 changed files with 61 additions and 19 deletions
|
@ -143,18 +143,7 @@ namespace System.Reflection
|
|||
|
||||
public Result<T> GetCustomAttribute<T>() where T : Attribute
|
||||
{
|
||||
if (mFieldData.mCustomAttributesIdx == -1)
|
||||
return .Err;
|
||||
|
||||
void* data = mTypeInstance.[Friend]mCustomAttrDataPtr[mFieldData.mCustomAttributesIdx];
|
||||
|
||||
T attrInst = ?;
|
||||
switch (AttributeInfo.GetCustomAttribute(data, typeof(T), &attrInst))
|
||||
{
|
||||
case .Ok: return .Ok(attrInst);
|
||||
default:
|
||||
return .Err;
|
||||
}
|
||||
return mTypeInstance.[Friend]GetCustomAttribute<T>(mFieldData.mCustomAttributesIdx);
|
||||
}
|
||||
|
||||
void* GetDataPtrAndType(Object value, out Type type)
|
||||
|
|
|
@ -54,6 +54,12 @@ namespace System.Reflection
|
|||
}
|
||||
}
|
||||
|
||||
public this(TypeInstance typeInstance, TypeInstance.MethodData* methodData)
|
||||
{
|
||||
mTypeInstance = typeInstance;
|
||||
mMethodData = methodData;
|
||||
}
|
||||
|
||||
public Type GetParamType(int paramIdx)
|
||||
{
|
||||
Debug.Assert((uint)paramIdx < (uint)mMethodData.mParamCount);
|
||||
|
@ -66,10 +72,9 @@ namespace System.Reflection
|
|||
return mMethodData.mParamData[paramIdx].mName;
|
||||
}
|
||||
|
||||
public this(TypeInstance typeInstance, TypeInstance.MethodData* methodData)
|
||||
public Result<T> GetCustomAttribute<T>() where T : Attribute
|
||||
{
|
||||
mTypeInstance = typeInstance;
|
||||
mMethodData = methodData;
|
||||
return mTypeInstance.[Friend]GetCustomAttribute<T>(mMethodData.mCustomAttributesIdx);
|
||||
}
|
||||
|
||||
public enum CallError
|
||||
|
|
|
@ -470,6 +470,13 @@ namespace System
|
|||
return FieldInfo.Enumerator(null, bindingFlags);
|
||||
}
|
||||
|
||||
public Result<T> GetCustomAttribute<T>() where T : Attribute
|
||||
{
|
||||
if (var typeInstance = this as TypeInstance)
|
||||
return typeInstance.[Friend]GetCustomAttribute<T>(typeInstance.[Friend]mCustomAttributesIdx);
|
||||
return .Err;
|
||||
}
|
||||
|
||||
public struct Enumerator : IEnumerator<Type>
|
||||
{
|
||||
int32 mCurId;
|
||||
|
@ -731,6 +738,22 @@ namespace System.Reflection
|
|||
{
|
||||
return FieldInfo.Enumerator(this, bindingFlags);
|
||||
}
|
||||
|
||||
Result<T> GetCustomAttribute<T>(int customAttributeIdx) where T : Attribute
|
||||
{
|
||||
if (customAttributeIdx == -1)
|
||||
return .Err;
|
||||
|
||||
void* data = mCustomAttrDataPtr[customAttributeIdx];
|
||||
|
||||
T attrInst = ?;
|
||||
switch (AttributeInfo.GetCustomAttribute(data, typeof(T), &attrInst))
|
||||
{
|
||||
case .Ok: return .Ok(attrInst);
|
||||
default:
|
||||
return .Err;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[CRepr, AlwaysInclude(AssumeInstantiated=true)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue