473,385 Members | 2,029 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,385 software developers and data experts.

How to extend an enum

I have an abstract base class with an enum which is passed into a
method. I want my derived classes to be able to add new values to the
enum without having to redefine it and I want to be able to pass them
into the method defined into the base class. Is there a way to do
this.

E.g.

abstract public class BaseWidget
{
public void Clear(Wodget wodget)
{
//do stuff with wodget
}

//other methods, etc.

public enum Wodget
{
wodget1, wodget2
}
}

public class LargeWidget: BaseWidget
{
//other methods, etc.

public enum Wodget
{
wodget3, wodget4
}
}

public class SmalllWidget: BaseWidget
{
//other methods, etc.

public enum Wodget
{
wodget5, wodget6
}
}
but I want the Wodget available to LargeWidget to contain wodgets 1, 2,
3 and 4 and the Wodget available to SmallWidget to contain wodgets 1,
2, 5 and 6.

I'd like this to be automatic so taht wodgets added to the base class
automatically appear in the derived class enums (otherwise I know that
someone's going to miss adding a new one to the derived class at some
point in the future.

Nov 17 '05 #1
3 11158
ssg31415926 wrote:
I have an abstract base class with an enum which is passed into a
method. I want my derived classes to be able to add new values to the
enum without having to redefine it and I want to be able to pass them
into the method defined into the base class. Is there a way to do
this.


I'm afraid you can't add anything to an enum. Could you give a bit more
detail about what you want to achieve here? There may well be a better
way - for instance, taking a variable number of enums, and when you
need to iterate, iterating through all of them.

Jon

Nov 17 '05 #2
"ssg31415926" <ne**********@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Is there a way to do this.


No.
Nov 17 '05 #3
Thanks. I've realised I was being a bit dim. In my getter/setters, I
couldn't pass a null or String.Empty to a wrapped object's setter
because the wrapped object's method wouldn't accept it. Instead, I had
to call a Clear function and pass it a property name. For some reason,
it didn't occur to me to put this in the setter and I was off writing a
generic clear function and using the enum to hold the name of the
property to be cleared! The solution came to me on the way to lunch.
I think maybe I had one too many last night!

Nov 17 '05 #4

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

Similar topics

20
by: Glenn Venzke | last post by:
I'm writing a class with a method that will accept 1 of 3 items listed in an enum. Is it possible to pass the item name without the enum name in your calling statement? EXAMPLE: public enum...
21
by: Andreas Huber | last post by:
Hi there Spending half an hour searching through the archive I haven't found a rationale for the following behavior. using System; // note the missing Flags attribute enum Color {
31
by: Michael C | last post by:
If a class inherits from another class, say Form inherits from control, then I can assign the Form to a variable of type Control without needing an explicit conversion, eg Form1 f = new Form1();...
2
by: centrino | last post by:
hi, I want to extend System.Net.Sockets.ProtocolType to IPinIP protocol, how can i do that. Do i have to make new class or enum stuct for this type ? regards
13
by: Don | last post by:
How do I get an Enum's type using only the Enum name? e.g. Dim enumType as System.Type Dim enumName as String = "MyEnum" enumType = ???(enumName)
1
by: Randy | last post by:
Hi, I downloaded and tried the ENUM++ code from CUJ http://www.cuj.com/documents/s=8470/cujboost0306besser/ but can't even get it to compile (see following). I have also downloaded and...
2
by: Randy | last post by:
Hi, I downloaded and tried the ENUM++ code from CUJ http://www.cuj.com/documents/s=8470/cujboost0306besser/ but can't even get it to compile (see following). I have also downloaded and...
4
by: Coder | last post by:
Hi, Running into an issue. I am creating a base class. This base class has a "State" property of type "States" which is a locally defined enum type. The issue is this...the derived class...
3
by: eXt | last post by:
For a realtime-application (half an application at least, kind of a framework) I am working with I need a event managing system and naturally it must be fast. I have defined a set of available...
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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...

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.