@@ -55,8 +55,8 @@ public static MethodInfo PrepareConvert(this Type fromType, Type toType)
5555 public static String GetOfficialName ( this MemberInfo member )
5656 {
5757 var names = member . GetCustomAttributes < DomNameAttribute > ( ) ;
58- var officalNameAttribute = names . FirstOrDefault ( ) ;
59- return officalNameAttribute ? . OfficialName ?? member . Name ;
58+ var officialNameAttribute = names . FirstOrDefault ( ) ;
59+ return officialNameAttribute ? . OfficialName ?? member . Name ;
6060 }
6161
6262 public static String GetOfficialName ( this Type currentType , Type baseType )
@@ -87,6 +87,18 @@ public static String GetOfficialName(this Type currentType, Type baseType)
8787 return name ;
8888 }
8989
90+ public static String GetOfficialName ( this Enum value )
91+ {
92+ var enumType = value . GetType ( ) ;
93+ var member = enumType . GetMember ( value . ToString ( ) ) . FirstOrDefault ( ) ;
94+
95+ // if the enum value does not have a DomNameAttribute, calling member.GetOfficialName() would return the value name
96+ // to allow previous behaviour to be preserved, if the DomNameAttribute is not present then null will be returned
97+ IEnumerable < DomNameAttribute > names = member . GetCustomAttributes < DomNameAttribute > ( ) ;
98+ var officialNameAttribute = names . FirstOrDefault ( ) ;
99+ return officialNameAttribute ? . OfficialName ;
100+ }
101+
90102 public static PropertyInfo GetInheritedProperty ( this Type type , String propertyName , BindingFlags bindingAttr = BindingFlags . Public | BindingFlags . Instance )
91103 {
92104 if ( type . GetTypeInfo ( ) . IsInterface )
0 commit comments