Exemplo n.º 1
0
        public static Guid Guid(this Enum e)
        {
            FieldInfo         fi        = e.GetType().GetField(e.ToString());
            EnumGuidAttribute attribute = fi.GetCustomAttribute <EnumGuidAttribute>();

            return(attribute.Guid);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        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);
        }