473,503 Members | 2,698 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Enumeration and Description

If I have an Enumeration can I give a text description for each value?

e.g. something like
Public Enum Colors

Black "Really cool Black"

Blue "Ice Cold Labatts"

End Enum
If so, how do I get the text description for each value?
Code snippet would be great.
Thanks!
--
Joe Fallon


Nov 20 '05 #1
4 1588
In article <uS**************@tk2msftngp13.phx.gbl>, jfallon1
@nospamtwcny.rr.com says...
If I have an Enumeration can I give a text description for each value?

e.g. something like
Public Enum Colors

Black "Really cool Black"

Blue "Ice Cold Labatts"

End Enum
If so, how do I get the text description for each value?
Code snippet would be great.


This link shows how to set the description as well as how to retrieve it
programatically:

http://tinyurl.com/3yc4o

--
Patrick Steele
Microsoft .NET MVP
http://weblogs.asp.net/psteele
Nov 20 '05 #2
Thanks!
Here is a more general version:
Public Shared Function GetDescription(ByVal value As [Enum]) As String

Dim fi As FieldInfo = value.GetType().GetField(value.ToString())

Dim attributes As DescriptionAttribute() =
CType(fi.GetCustomAttributes(GetType(DescriptionAt tribute), False),
DescriptionAttribute())

If attributes.Length > 0 Then

Return attributes(0).Description()

Else

Return value.ToString()

End If

End Function
--
Joe Fallon
"Patrick Steele [MVP]" <pa*****@mvps.org> wrote in message
news:MP************************@msnews.microsoft.c om...
In article <uS**************@tk2msftngp13.phx.gbl>, jfallon1
@nospamtwcny.rr.com says...
If I have an Enumeration can I give a text description for each value?

e.g. something like
Public Enum Colors

Black "Really cool Black"

Blue "Ice Cold Labatts"

End Enum
If so, how do I get the text description for each value?
Code snippet would be great.


This link shows how to set the description as well as how to retrieve it
programatically:

http://tinyurl.com/3yc4o

--
Patrick Steele
Microsoft .NET MVP
http://weblogs.asp.net/psteele

Nov 20 '05 #3
"Joe Fallon" <jf******@nospamtwcny.rr.com> schrieb
If I have an Enumeration can I give a text description for each
value?

e.g. something like
Public Enum Colors

Black "Really cool Black"

Blue "Ice Cold Labatts"

End Enum
If so, how do I get the text description for each value?
Code snippet would be great.


No, not possible. You could create a class containing a short and long
description, like:

public class mycolor
public readonly Name as string
public readonly Description as string
public sub new(name as string,description as string)
me.name = name
me.description = description
end sub
end class

Optionally/in addition:

public class mycolor
public readonly Name as string
public readonly Description as string
private sub new(name as string,description as string)
me.name = name
me.description = description
end sub
public shared readonly Blue as new mycolor _
("Blue", "Ice Cold Labatts")
end class
- or an arraylist with key=name and value=description, or...
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #4
"Joe Fallon" <jf******@nospamtwcny.rr.com> wrote in message
news:uS**************@tk2msftngp13.phx.gbl...
If I have an Enumeration can I give a text description for each value?


As I see things, the main point of using Enumerations is to make the
"values" within them more meaningful in their own right - self-describing,
if you like - and less like the "Magic Numbers" that we all know and
love ;-)

So, if you want to give your colours names, go for it ...

Public Enum Colours
ReallyCoolBlack = &H0
IceColdLabatts = &HFF0000
. . .

(OK, they're VB6 colour codes - I haven't got to the .Net ones yet).

HTH,
Phill W.
Nov 20 '05 #5

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

Similar topics

1
12616
by: Justin Wright | last post by:
I know that I can set up an enumeration as follows ( just typed in quick so may have syntax errors ): <xsd:simpleType name="colors"> <xsd:restriction base="xsd:string"> <xsd:enumeration...
0
1142
by: Stephan Steiner | last post by:
Hi I'm not sure where to post this, so since I came to it when searching the ..net API documentation in c# mode I'll post it here. Have a look at the 4 items below. It appears to me that two...
2
1797
by: Mark | last post by:
Assume you have an enumeration like PhoneType { Home, Business, Cell }. This enumeration corresponds with a lookup/dictionary table in your database like: phone_cd | phone_descr 1 ...
4
5643
by: Marshal | last post by:
Sure... IEnumerable was inconvenient suggesting a separate class to service the enumeration, IEnumerator, and multiple operations: Current, MoveNext, Reset. (I'll warp the definition of "operation"...
8
1713
by: John Cobb | last post by:
Excuse me if I use some terminology incorrectly as I am not well versed in Object Orientation. In short I want to create an Enumerated type similar to the following Enum Monitor as Byte Small...
3
2527
by: Davidoff | last post by:
Hi, I parse an XML file with a XSD schema. One XmlNode has an attribute whose type is a restriction of xs:string : <xs:simpleType name="stypeDay"> <xs:restriction base="xs:string">...
7
4433
by: Nathan | last post by:
I'd like to use an enumeration as a datasource for a drop-down box. Is there a way to do this?
0
500
by: news.emn.fr | last post by:
Hello, i got this attribute <xs:attribute name="jour"> <xs:simpleType> <xs:restriction base="stypeJour"> </xs:restriction> </xs:simpleType> </xs:attribute>
2
2542
by: Daniel Jeffrey | last post by:
Hello. Can anyone help me please. I have created an Enumeration, and I loop through it, it all works ok, except the first item returns 2 times. Code is below. When called I Get "Text Edit" 2...
0
7192
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7064
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7261
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7315
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7445
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
3147
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1492
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
369
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.