@@ -23,4 +23,55 @@ public static T GetResourceLookup<T>(Type resourceType, string resourceName)
2323 return default ( T ) ;
2424 }
2525 }
26+
27+ /// <summary>
28+ /// Group of helpers that gets Display attributes values from Enum members
29+ /// DražaM
30+ /// </summary>
31+ public static class EnumHelper
32+ {
33+ public static string DisplayName ( this Enum value )
34+ {
35+ Type enumType = value . GetType ( ) ;
36+ var enumValue = Enum . GetName ( enumType , value ) ;
37+ MemberInfo member = enumType . GetMember ( enumValue ) [ 0 ] ;
38+
39+ var attrs = member . GetCustomAttributes ( typeof ( DisplayAttribute ) , false ) ;
40+ var outString = member . Name ;
41+ if ( attrs . Length > 0 )
42+ {
43+
44+ if ( ( ( DisplayAttribute ) attrs [ 0 ] ) . ResourceType != null )
45+ {
46+ outString = ( ( DisplayAttribute ) attrs [ 0 ] ) . GetName ( ) ;
47+ }
48+ else
49+ {
50+ outString = ( ( DisplayAttribute ) attrs [ 0 ] ) . Name ;
51+ }
52+ }
53+ return outString ;
54+ }
55+
56+ public static List < string > AllDisplayNames ( this Type tip )
57+ {
58+ List < string > exitList = new List < string > ( ) ;
59+ foreach ( string r in Enum . GetNames ( tip ) )
60+ {
61+ exitList . Add ( ( ( Enum ) Enum . Parse ( tip , r ) ) . DisplayName ( ) ) ;
62+ } ;
63+ return exitList ;
64+ }
65+
66+ public static object [ ] EnumValLabPairs ( this Type type )
67+ {
68+ var vals = Enum . GetNames ( type ) . Cast < object > ( ) . ToArray ( ) ;
69+ var lbls = type . AllDisplayNames ( ) . Cast < object > ( ) . ToArray ( ) ;
70+ var result = new List < object > ( ) ;
71+
72+ for ( var x = 0 ; x <= vals . Length - 1 ; x ++ ) { result . Add ( new { value = vals [ x ] , label = lbls [ x ] } ) ; }
73+
74+ return result . ToArray < object > ( ) ;
75+ }
76+ }
2677}
0 commit comments