using System; /// /// Get custom attribute extension /// public static class EnumExtension { /// /// Check if enum has attribute type /// Example usage bool c = Biz.SockType.License.HasAttribute(typeof(Biz.AttachableAttribute)); /// /// /// /// /// 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; } }