C#: Wrapping one Enum inside another (ie. mirroring another enum/copying it...)

18,386

What you are asking has been discussed here:

Enum "Inheritance"

Share:
18,386

Related videos on Youtube

AlishahNovin
Author by

AlishahNovin

(my About Me is currently blank)

Updated on April 16, 2022

Comments

  • AlishahNovin
    AlishahNovin about 2 years

    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)
    }
    
  • Stan R.
    Stan R. over 14 years
    this is more work than simply mapping out the Enum yourself...i don't necessarily think its worth it.