DragonECS/src/Internal/ReflectionUtility.cs

33 lines
1.2 KiB
C#
Raw Normal View History

2024-03-06 21:35:34 +08:00
using System;
using System.Reflection;
using System.Runtime.CompilerServices;
namespace DCFApixels.DragonECS.Internal
{
internal static class ReflectionUtility
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
2024-09-30 19:29:19 +08:00
public static bool TryGetAttribute<T>(this MemberInfo self, out T attribute) where T : Attribute
2024-03-06 21:35:34 +08:00
{
attribute = self.GetCustomAttribute<T>();
return attribute != null;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
2024-09-30 19:29:19 +08:00
public static bool TryGetAttribute<T>(this MemberInfo self, bool inherit, out T attribute) where T : Attribute
2024-03-06 21:35:34 +08:00
{
2024-09-30 19:29:19 +08:00
attribute = self.GetCustomAttribute<T>(inherit);
2024-03-06 21:35:34 +08:00
return attribute != null;
}
2024-09-30 19:29:19 +08:00
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool HasAttribute<T>(this MemberInfo self) where T : Attribute
{
return self.GetCustomAttribute<T>() != null;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool HasAttribute<T>(this MemberInfo self, bool inherit) where T : Attribute
{
return self.GetCustomAttribute<T>(inherit) != null;
}
2024-03-06 21:35:34 +08:00
}
}