Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Description Attribute Retrieval for Enum Type?

4 views
Skip to first unread message

Schorschi

unread,
Dec 2, 2003, 9:07:28 PM12/2/03
to
I know I have seen this in C# somewhere, but can't seem to find the
right note, but need it in VB .Net!

Public Enum Numbers
<Description("This is 10.")> Ten = 10
<Description("This is 11.")> Eleven = 11
End Enum

How do I get the descrition text via code?

Dim theString As String = ???

Thx.

Mattias Sjögren

unread,
Dec 3, 2003, 1:47:37 AM12/3/03
to

>How do I get the descrition text via code?
>
>Dim theString As String = ???

Dim ten As FieldInfo = GetType(Numbers).GetField("Ten")
Dim attr As DescriptionAttribute =
DirectCast(ten.GetCustomAttributes(GetType(DescriptionAttribute),
False)(0), DescriptionAttribute)
theString = attr.Description

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.

0 new messages