DisplayName through Reflection

  • Thread starter Thread starter Charles Bazi
  • Start date Start date
C

Charles Bazi

Hi,

I have some properties using System.ComponentModel.DisplayName

How can I retrieve that value using Reflection ?

TIA
 
Hi,

I have some properties using System.ComponentModel.DisplayName

How can I retrieve that value using Reflection ?

TIA

Look at system.reflection.propertyinfo. That will let you call the property.
You can get the property using one of the Type.GetProperty overloads.
 
I got the DisplayName this way:

private string getDisplayName ( MemberInfo mi ) {

object[] atts = mi.GetCustomAttributes( typeof( DisplayNameAttribute ),
false );
if(atts.Length > 0) {
DisplayNameAttribute da = atts[0] as DisplayNameAttribute;
return da.DisplayName;
}
return mi.Name;
}

Then I use it in my foreach(PropertyInfo p in properties)

mything.label = getDisplayName(p);

Found info here: http://forums.devx.com/showpost.php?p=441665&postcount=2

Thank you
 
Back
Top