13

Here's my problem: I have an object that's referencing a DLL. I would like other objects to reference my object, without having to also include a reference to the DLL itself.

This is fine for the most part except there is an enum in the DLL that I would like to replicate. I could write out the enum line by line, but I'm wondering if there's a better way to do this.

ie.

Let's say the DLL's got the following enum:

public enum dllEnum
{
  value1,
  value2,
  value3
}

I could do the following:

public enum myEnum
{
  value1,
  value2,
  value3
}

or better yet:

public enum myEnum
{
  value1 = dllEnum.value1,
  value2 = dllEnum.value2,
  value3 = dllEnum.value3
}

But each of these cases has me writing out the entire enum out myself. I would rather just be able to wrap the entire enum as my own, preserving the indexes of the original enum.

Something along the lines of:

public enum myEnum
{
  Enum.GetValues(dllEnum)
}
AlishahNovin
  • 1,904
  • 3
  • 20
  • 37

2 Answers2

11

What you are asking has been discussed here:

Enum "Inheritance"

Community
  • 1
  • 1
Michael Edwards
  • 6,308
  • 6
  • 44
  • 75
0

http://social.msdn.microsoft.com/forums/en-US/netfxbcl/thread/ddedaf59-fb36-45cd-8062-446fa92d8f68

This article has some great examples that may help you get to a solution whereby you dynamically generate your enum and compile it at runtime. I've done this for an 'eval' type function in VB.Net, but I haven't done it for an enum.

This would not allow for compile time checking of values, so you would be in a world of hurt in a lot of ways there. With the DLR in .Net 4.0, I imagine that you'd have more flexibility (though I admit, I haven't read details of the next version of the framework.)

Kevin Buchan
  • 2,790
  • 3
  • 27
  • 34
  • this is more work than simply mapping out the Enum yourself...i don't necessarily think its worth it. – Stan R. Dec 02 '09 at 17:59