Discovering attributes of a object.

C

Chris Dunaway

Consider the following simple class:

Class Test
Private _MyInteger As Integer

<Description("This is my personal integer value!"), _
Category("Personal")> _
Public Property MyInteger() As Integer
Get
Return _MyInteger
End Get
Set(ByVal Value As Integer)
_MyInteger = Value
End Set
End Property

End Class

If I have an instance of this class:

Dim obj As New Test


How can I get the values of the attribute (Description and Category) from
the object instance?

The PropertyGrid does it somehow. I would like to do it as well but have
been unable to figure it out.


--
Chris

dunawayc[AT]sbcglobal_lunchmeat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
 
I

Imran Koradia

you can use Attribute.GetCustomAttributes(Assembly.GetExecutingAssembly,
obj.GetType)
this will give you a collection of attribute objects - one for each custom
attribute in your class.

hope this helps..
Imran.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top