473,770 Members | 1,862 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 1604
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 DescriptionAttr ibute() =
CType(fi.GetCus tomAttributes(G etType(Descript ionAttribute), False),
DescriptionAttr ibute())

If attributes.Leng th > 0 Then

Return attributes(0).D escription()

Else

Return value.ToString( )

End If

End Function
--
Joe Fallon
"Patrick Steele [MVP]" <pa*****@mvps.o rg> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
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******@nospa mtwcny.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,descript ion 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,descript ion 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=descripti on, 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******@nospa mtwcny.rr.com> wrote in message
news:uS******** ******@tk2msftn gp13.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
12633
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 value="red"/> <xsd:enumeration value="yellow"/> <xsd:enumeration value="blue"/> </xsd:simpleType>
0
1155
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 descriptions have been interchanged: ReceiveBuffer Send low water mark. ReceiveLowWater Receive low water mark.
2
1814
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 Home 2 Business 3 Cell Now, I could associated each enumeration value with the phone_cd used in the
4
5660
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" for a second if you don't mind). However, it existed within intuitive language semantics, whereas the new "yield" keyword, while highly convenient, is also one of the most gross warping of language concepts to date... public IEnumerator...
8
1729
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 Medium Large End Enum
3
2548
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"> <xs:enumeration value="Mon"/> <xs:enumeration value="Tue"/> <xs:enumeration value="Wed"/>
7
4457
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
2557
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 times public enum CustomFieldTypes
0
9617
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10037
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9904
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8931
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7456
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
4007
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 we have to send another system
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2849
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.