Solved

howto get displayname attribute of an property in a class

Posted on 2007-12-04
1
1,421 Views
Last Modified: 2013-11-25
public class MyClass
    <DisplayName("ISO-code")> _
    Public  Property IsoCode() As String
0
Comment
Question by:ecapro
1 Comment
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 125 total points
ID: 20402462
try with this:

            Dim DisplayName as String
           ' Get the type of MyClass1.
            Dim myType as Type = TypeOf(MyClass1)
            ' Get the property info
            Dim pop as PropertyInfo = myType.GetProperty("DisplayName")
            ' Get attribute list
            Dim attrs() as Object = prop.GetCustomAttribues(TypeOf(DisplayNameAttribute), False)
            ' check if attribute exists
            If attrs.Length > 0
                   DisplayName = DirectCast(attrs(0), DisplayNameAttribute).DisplayName
                   
           
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question