473,322 Members | 1,522 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

DisplayName through Reflection

Hi,

I have some properties using System.ComponentModel.DisplayName

How can I retrieve that value using Reflection ?

TIA
Nov 30 '06 #1
2 3266
On 2006-11-30, Charles Bazi <cb***@noos.frwrote:
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
Dec 1 '06 #2


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:
On 2006-11-30, Charles Bazi <cb***@noos.frwrote:
>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
Dec 3 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: A. Wiebenga | last post by:
Hi all! I am a student at the Hogeschool van Arnhem en Nijmegen in Holland. I am currently involved in a research project regarding Reflection. Purpose of the research project is to document...
10
by: Sunny | last post by:
Hi, I have an old problem which I couldn't solve so far. Now I have found a post in that group that gave me an idea, but I can not fully understand it. The problem is: I'm trying to use a...
0
by: Shawn Hogan | last post by:
Hi everyone, I've been trying to execute a control's private event code via reflection from another class with the goal of potentially doing some unit testing. The examples below are trying to...
1
by: Jay | last post by:
Hey There, I have some code that will go through a couple of sections of the registry, and create a list that contains the "DisplayName" values of all the apps that are listed in the Add/Remove...
9
by: Kuberan Naganathan | last post by:
Hello all Does anyone know of a good way to use reflection in c++? I don't mean simply using rtti or dynamic casting. I'm talking about java/c# style reflection where an actual instance of...
17
by: raylopez99 | last post by:
What good is C# Reflection, other than to find out what types are in an assembly? And to dynamically invoke methods in an assembly (.dll or .exe)? Also, bonus question, can you use Reflection...
0
by: Gustavo Arriola | last post by:
Hola a todos! Estoy intentando ejecutar un método usando Reflection. El código es el siguiente: public static void SoapHandler(Exception Error) { try { Type assemblyType;
6
by: Cralis | last post by:
Hi guys, Someone once said, 'You can do that with reflection'. I can't recall what it was I was trying to do at the time, but then he said, 'Any developer knows what reflection is...'. I kept...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.