public static Guid Guid(this Enum e) { FieldInfo fi = e.GetType().GetField(e.ToString()); EnumGuidAttribute attribute = fi.GetCustomAttribute <EnumGuidAttribute>(); return(attribute.Guid); }
public static Guid Guid(this Enum e) { FieldInfo fi = e.GetType().GetField(e.ToString()); // changed for .net framework 4.0 // EnumGuidAttribute attribute = fi.GetCustomAttribute<EnumGuidAttribute>(); EnumGuidAttribute attribute = Attribute.GetCustomAttribute(fi, typeof(EnumGuidAttribute)) as EnumGuidAttribute; return(attribute.Guid); }
public static T GetEnum <T>(this Guid guid) where T : struct { T en = Enum.GetValues(typeof(T)).Cast <T>().Where(e => { EnumGuidAttribute ea = e.GetType().GetField(e.ToString()).GetCustomAttribute <EnumGuidAttribute>(); return(ea.Guid == guid); }).FirstOrDefault(); return(en); }
public static T GetEnum <T>(this Guid guid) where T : struct { T en = Enum.GetValues(typeof(T)).Cast <T>().Where(e => { // changed for .net framework 4.0 // EnumGuidAttribute ea = e.GetType().GetField(e.ToString()).GetCustomAttribute<EnumGuidAttribute>(); EnumGuidAttribute ea = Attribute.GetCustomAttribute(e.GetType().GetField(e.ToString()), typeof(EnumGuidAttribute)) as EnumGuidAttribute; return(ea.Guid == guid); }).FirstOrDefault(); return(en); }