This commit is contained in:
2022-12-16 06:01:23 +00:00
parent 26c2ae5cc9
commit effd96143f
310 changed files with 48715 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
using System;
/// <summary>
/// Get custom attribute extension
/// </summary>
public static class EnumExtension
{
/// <summary>
/// Check if enum has attribute type
/// Example usage bool c = Biz.SockType.License.HasAttribute(typeof(Biz.AttachableAttribute));
///
/// </summary>
/// <param name="value"></param>
/// <param name="t"></param>
/// <returns></returns>
public static bool HasAttribute(this Enum value, Type t)
{
var type = value.GetType();
var name = Enum.GetName(type, value);
if (name != null)
{
var field = type.GetField(name);
if (field != null)
{
var attr =
Attribute.GetCustomAttribute(field, t);
if (attr != null)
{
return true;
}
}
}
return false;
}
}