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

Added HasCustomAttribute to MethodInfo/FieldInfo

This commit is contained in:
Brian Fiete 2022-05-26 06:43:09 -07:00
parent da29789bd6
commit bbd0fe8779
2 changed files with 36 additions and 0 deletions

View file

@ -230,6 +230,24 @@ namespace System.Reflection
*((*(T2**)&data)++) *((*(T2**)&data)++)
} }
public bool HasCustomAttribute<T>() where T : Attribute
{
if (Compiler.IsComptime)
{
int32 attrIdx = -1;
Type attrType = null;
repeat
{
attrType = Type.[Friend]Comptime_Field_GetCustomAttributeType((int32)mTypeInstance.TypeId, mFieldData.mCustomAttributesIdx, ++attrIdx);
if (attrType == typeof(T))
return true;
}
while (attrType != null);
return false;
}
return mTypeInstance.[Friend]HasCustomAttribute<T>(mFieldData.mCustomAttributesIdx);
}
public Result<T> GetCustomAttribute<T>() where T : Attribute public Result<T> GetCustomAttribute<T>() where T : Attribute
{ {
if (Compiler.IsComptime) if (Compiler.IsComptime)

View file

@ -133,6 +133,24 @@ namespace System.Reflection
return mTypeInstance.[Friend]GetCustomAttributes<T>(mData.mMethodData.mParamData[paramIdx].mCustomAttributesIdx); return mTypeInstance.[Friend]GetCustomAttributes<T>(mData.mMethodData.mParamData[paramIdx].mCustomAttributesIdx);
} }
public bool HasCustomAttribute<T>() where T : Attribute
{
if (Compiler.IsComptime)
{
int32 attrIdx = -1;
Type attrType = null;
repeat
{
attrType = Type.[Friend]Comptime_Method_GetCustomAttributeType(mData.mComptimeMethodInstance, ++attrIdx);
if (attrType == typeof(T))
return true;
}
while (attrType != null);
return false;
}
return mTypeInstance.[Friend]HasCustomAttribute<T>(mData.mMethodData.mCustomAttributesIdx);
}
public Result<T> GetCustomAttribute<T>() where T : Attribute public Result<T> GetCustomAttribute<T>() where T : Attribute
{ {
if (Compiler.IsComptime) if (Compiler.IsComptime)