HighTechTalks DotNet Forums  

DisplayName through Reflection

Dotnet General Discussions microsoft.public.dotnet.general


Discuss DisplayName through Reflection in the Dotnet General Discussions forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Charles Bazi
 
Posts: n/a

Default DisplayName through Reflection - 11-30-2006 , 03:21 PM






Hi,

I have some properties using System.ComponentModel.DisplayName

How can I retrieve that value using Reflection ?

TIA

Reply With Quote
  #2  
Old   
Tom Shelton
 
Posts: n/a

Default Re: DisplayName through Reflection - 12-01-2006 , 12:01 AM






On 2006-11-30, Charles Bazi <cbazi (AT) noos (DOT) fr> wrote:
Quote:
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.

--
Tom Shelton


Reply With Quote
  #3  
Old   
Charles Bazi
 
Posts: n/a

Default Re: DisplayName through Reflection - 12-03-2006 , 12:49 PM





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?...65&postcount=2

Thank you

Tom Shelton wrote:
Quote:
On 2006-11-30, Charles Bazi <cbazi (AT) noos (DOT) fr> wrote:
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.

--
Tom Shelton

Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.