1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-07-04 07:15:59 +02:00

Comptime GetCustomAttribute for type/field/method

This commit is contained in:
Brian Fiete 2022-02-17 05:51:05 -05:00
parent 434a7406de
commit 4c5c89bab5
8 changed files with 110 additions and 13 deletions

View file

@ -229,6 +229,13 @@ namespace System.Reflection
public Result<T> GetCustomAttribute<T>() where T : Attribute
{
if (Compiler.IsComptime)
{
T val = ?;
if (Type.[Friend]Comptime_Field_GetCustomAttribute((int32)mTypeInstance.TypeId, mFieldData.mCustomAttributesIdx, (.)typeof(T).TypeId, &val))
return val;
return .Err;
}
return mTypeInstance.[Friend]GetCustomAttribute<T>(mFieldData.mCustomAttributesIdx);
}

View file

@ -95,7 +95,12 @@ namespace System.Reflection
public Result<T> GetCustomAttribute<T>() where T : Attribute
{
if (Compiler.IsComptime)
{
T val = ?;
if (Type.[Friend]Comptime_Method_GetCustomAttribute(mData.mComptimeMethodInstance, (.)typeof(T).TypeId, &val))
return val;
return .Err;
}
return mTypeInstance.[Friend]GetCustomAttribute<T>(mData.mMethodData.mCustomAttributesIdx);
}

View file

@ -529,6 +529,8 @@ namespace System
static extern String Comptime_Type_ToString(int32 typeId);
static extern Type Comptime_GetSpecializedType(Type unspecializedType, Span<Type> typeArgs);
static extern bool Comptime_Type_GetCustomAttribute(int32 typeId, int32 attributeId, void* dataPtr);
static extern bool Comptime_Field_GetCustomAttribute(int32 typeId, int32 fieldIdx, int32 attributeId, void* dataPtr);
static extern bool Comptime_Method_GetCustomAttribute(int64 methodHandle, int32 attributeId, void* dataPtr);
static extern int32 Comptime_GetMethodCount(int32 typeId);
static extern int64 Comptime_GetMethod(int32 typeId, int32 methodIdx);
static extern String Comptime_Method_ToString(int64 methodHandle);