473,587 Members | 2,524 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 11176
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
"ssg3141592 6" <ne**********@g mail.com> wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.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
4820
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 EnumName FirstValue = 1 SecondValue = 2 ThirdValue = 3
21
4580
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
3583
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(); Control c = f; An enum value inherits from int but it doesn't get implicitly converted: HorizontalAlignment h = HorizontalAlignment.Center;
2
2207
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
12371
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
2450
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 installed the boost library. This is using gcc under FC3.
2
2112
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 installed the boost library. This is using gcc under FC3.
4
2412
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 apparently can't add to the "States" enum. In other words, if the derived class wanted to define another state, it can't. At this point, I am...
3
2703
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 event types in an enumeration like this: enum Events { EVENT_FOO, EVENT_BAR, EVENT_BAZ, EVENT_CUSTOM1,
0
7918
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...
0
8340
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
5713
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...
0
5392
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3840
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3875
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2353
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
1
1452
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1185
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...

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.