473,383 Members | 1,870 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Handling Enumerations

Enumerations are pretty useful. But the one recurring problem I have had
with using them is the inevitably, the list of options being enumerated
grows. Then the program has to be recompiled to account for the new
options.

For cases like this where the list of options can change over time, is there
an alternative to the enumeration that captures the same functionality?

Thanks,
Joe
Nov 20 '05 #1
1 874
* "Joe H" <jh****@hotmail.com> scripsit:
Enumerations are pretty useful. But the one recurring problem I have had
with using them is the inevitably, the list of options being enumerated
grows. Then the program has to be recompiled to account for the new
options.

For cases like this where the list of options can change over time, is there
an alternative to the enumeration that captures the same functionality?


Maybe following this pattern helps:

\\\
Public Structure ClipboardType
Public Shared ReadOnly Property Rtf() As ClipboardType
Get
Return New ClipboardType("RTF") ' Don't cache them ;-).
End Get
End Property

Public Shared ReadOnly Property Bitmap() As ClipboardType
Get
Return New ClipboardType("Bitmap")
End Get
End Property

Public Shared ReadOnly Property Text() As ClipboardType
Get
Return New ClipboardType("Text")
End Get
End Property

Private Sub New(ByVal Value As String)
m_Value = Value
End Sub

Private m_Value As String

' Alternatively, we could implement a 'ReadOnly' 'Value'
' property or something similar.
Public Overrides Function ToString() As String
Return m_Value
End Function

Public Overloads Overrides Function Equals( _
ByVal obj As Object _
) As Boolean
Return _
DirectCast(obj, ClipboardType).ToString() = m_Value
End Function

' '=' Operator overloading stuff goes here (VB 2005).
End Structure
///

Usage:

\\\
Public Sub Foo(ByVal c As ClipboardType)
MsgBox(c.Equals(ClipboardType.Rtf))
MsgBox(c.Equals(ClipboardType.Bitmap))
MsgBox(ClipboardType.Rtf.ToString()) ' Get the value.
End Sub

Public Sub Test()
Foo(ClipboardType.Bitmap)
End Sub
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #2

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

Similar topics

1
by: Joyce | last post by:
In my schema I have 2 enumerations, let's say, country description and country code, and I want to use them so I can map each country description to its precise country code (and no other). So far...
0
by: Plinkerton | last post by:
I'm making an Base Class that will be inherited. In my base class, I have a public enumeration that defines a list of things I want my class to be able to do. I use it for Method input...
21
by: Christopher Benson-Manica | last post by:
I'll try to explain what I want to do: I have foo.h and foo.cpp. Units that include foo.h will define an enumeration bar: enum bar { typeNone, typeBaz, typeQuux, ... , count }; A method...
3
by: JoeH | last post by:
Hi, I'm using a COM DLL (created in VB) in my javascript code and can successfully call its methods and get/set its properties. There are also some Public enumerations defined in the ActiveX...
1
by: someone else | last post by:
I have some code that creates dynamic enumerations for use in a PropertyGrid control. This all works perfectly but the memory usage of the program increases quite quicly when viewing the...
1
by: Oleg Ogurok | last post by:
Hi all, I've added a new DataSet (xsd file) to my project in VS.NET 2003. There I create a simple type as an enumeration of values. <xs:simpleType name="MyCustomType"> <xs:restriction...
4
by: ChrisB | last post by:
Hello: I will be creating 50+ enumerations related to a large number of classes that span a number of namespaces. I was wondering if there are any "best practices" when defining enumerations. ...
27
by: Ben Finney | last post by:
Antoon Pardon wrote: > I just downloaded your enum module for python > and played a bit with it. IMO some of the behaviour makes it less > usefull. Feedback is appreciated. I'm hoping to...
77
by: Ben Finney | last post by:
Howdy all, PEP 354: Enumerations in Python has been accepted as a draft PEP. The current version can be viewed online: <URL:http://www.python.org/peps/pep-0354.html> Here is the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.