1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-17 15:46:05 +02:00

Some refactoring and add GetCustomAttributes for Comptime

This commit is contained in:
disarray2077 2022-02-26 22:31:32 -03:00
parent d52ebfa1db
commit 3df708779d
8 changed files with 557 additions and 97 deletions

View file

@ -112,9 +112,19 @@ namespace System.Reflection
{
if (Compiler.IsComptime)
{
T val = ?;
if (Type.[Friend]Comptime_Method_GetCustomAttribute(mData.mComptimeMethodInstance, (.)typeof(T).TypeId, &val))
return val;
int32 attrIdx = -1;
Type attrType = null;
repeat
{
attrType = Type.[Friend]Comptime_Method_GetCustomAttributeType(mData.mComptimeMethodInstance, ++attrIdx);
if (attrType == typeof(T))
{
T val = ?;
if (Type.[Friend]Comptime_Method_GetCustomAttribute(mData.mComptimeMethodInstance, attrIdx, &val))
return val;
}
}
while (attrType != null);
return .Err;
}
return mTypeInstance.[Friend]GetCustomAttribute<T>(mData.mMethodData.mCustomAttributesIdx);
@ -122,18 +132,26 @@ namespace System.Reflection
public AttributeInfo.CustomAttributeEnumerator GetCustomAttributes()
{
if (Compiler.IsComptime)
Runtime.NotImplemented();
return mTypeInstance.[Friend]GetCustomAttributes(mData.mMethodData.mCustomAttributesIdx);
}
[Comptime]
public AttributeInfo.ComptimeMethodCustomAttributeEnumerator GetCustomAttributes()
{
return .(mData.mComptimeMethodInstance);
}
public AttributeInfo.CustomAttributeEnumerator<T> GetCustomAttributes<T>() where T : Attribute
{
if (Compiler.IsComptime)
Runtime.NotImplemented();
return mTypeInstance.[Friend]GetCustomAttributes<T>(mData.mMethodData.mCustomAttributesIdx);
}
[Comptime]
public AttributeInfo.ComptimeMethodCustomAttributeEnumerator<T> GetCustomAttributes<T>() where T : Attribute
{
return .(mData.mComptimeMethodInstance);
}
public Result<T> GetReturnCustomAttribute<T>() where T : Attribute
{
if (Compiler.IsComptime)