Inheriting From An Enum?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am developing a class that inherits the Event Log Class. I want to make the EventLogEntryType enum available as part of the same namespace as the class I am writing but I don't think I can inherit from an enum. Any way to make this happen so that the client doesn't have to use the System.Diagnostics namespace?
 
Enums are value types so you can't inherit from them. If you want to do this
you'll have to recreate the enum within your own namespace.

You can use a function like this one to ease the pain of mapping the values:

static void DumpEnum(System.Type t, string name) {

MemberInfo[] mis = t.FindMembers(MemberTypes.Field,
BindingFlags.Static | BindingFlags.Public,
Type.FilterNameIgnoreCase, "*");

foreach (MemberInfo mi in mis) {
FieldInfo fi = mi as FieldInfo;
Debug.WriteLine(string.Format("{0} = {1},", mi.Name, (int)
fi.GetValue(null)));
}

}

Just place the output inside your enum block declaration =)


--
____________________
Klaus H. Probst, MVP
http://www.vbbox.com/

Dan Thompson said:
I am developing a class that inherits the Event Log Class. I want to make
the EventLogEntryType enum available as part of the same namespace as the
class I am writing but I don't think I can inherit from an enum. Any way to
make this happen so that the client doesn't have to use the
System.Diagnostics namespace?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top