locked
How do I export an enum from my dll? RRS feed

  • Question

  • I have a class that contains a public [Flags]enum{...} listing possible errors.  I also have a public property of the enum type, to make the errors available to the user of my class.  Everything seems in order, but the ObjectBrowser shows that the enum is not being exported.

    How do I export an enum from my dll?


    JimT 2000

    Friday, April 12, 2013 4:14 PM

Answers

  • Take the enum definition out of the class and make it a assembly level enum. So instead of:

    public class MyClass
    {
        public enum MyEnum
        {
            ...
        }
    
        ...
    }

    You should have:

    public enum MyEnum
    {
        ...
    }
    
    public class MyClass
    {
        ...
    }

    Or even put the enum in its own .cs file.

    • Proposed as answer by mbj79 Saturday, April 13, 2013 1:25 PM
    • Marked as answer by JimT 2000 Monday, April 15, 2013 7:31 PM
    Friday, April 12, 2013 7:01 PM
  • > "... but the ObjectBrowser shows that the enum is not being exported."

    If your enum is a nested enum within your class, then it should show up in the object browser as same-level sibling to its container class within their namespace. Is your class name ClassA and your enum named Enum, then the latter shows up in the object browser as ClassA:Enum. If you have very complicated namespaces with a lot of classes and subclasses this sometimes can be confusing.

    If you want to reference an public enum that is nested within one class from another class you have to use the fully qualified name. If you want to use the nested enum outside its container class, I'm not sure about your intention from what you told us so far, you should consider Hasani Holder's advice to define it directly within a namespace.

    Kind regards,

    wizend

    • Marked as answer by JimT 2000 Monday, April 15, 2013 7:31 PM
    Saturday, April 13, 2013 12:57 PM

All replies

  • Exported?

    Normally I jsut add a reference to the dll and all Public types are found.

    So how do you "Export" the dll? Is this going across Binary Formats (trying to use a native C++ Library in .NET?).


    Let's talk about MVVM: http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/b1a8bf14-4acd-4d77-9df8-bdb95b02dbe2

    Friday, April 12, 2013 4:22 PM
  • Take the enum definition out of the class and make it a assembly level enum. So instead of:

    public class MyClass
    {
        public enum MyEnum
        {
            ...
        }
    
        ...
    }

    You should have:

    public enum MyEnum
    {
        ...
    }
    
    public class MyClass
    {
        ...
    }

    Or even put the enum in its own .cs file.

    • Proposed as answer by mbj79 Saturday, April 13, 2013 1:25 PM
    • Marked as answer by JimT 2000 Monday, April 15, 2013 7:31 PM
    Friday, April 12, 2013 7:01 PM
  • > "... but the ObjectBrowser shows that the enum is not being exported."

    If your enum is a nested enum within your class, then it should show up in the object browser as same-level sibling to its container class within their namespace. Is your class name ClassA and your enum named Enum, then the latter shows up in the object browser as ClassA:Enum. If you have very complicated namespaces with a lot of classes and subclasses this sometimes can be confusing.

    If you want to reference an public enum that is nested within one class from another class you have to use the fully qualified name. If you want to use the nested enum outside its container class, I'm not sure about your intention from what you told us so far, you should consider Hasani Holder's advice to define it directly within a namespace.

    Kind regards,

    wizend

    • Marked as answer by JimT 2000 Monday, April 15, 2013 7:31 PM
    Saturday, April 13, 2013 12:57 PM
  • Christopher,

    Hasani,

    Thank you for your help.  I rearranged the code to take the enum out of the class and it works exactly as I originally intended.  My test program creates errors and reports them by name instead of as an integer that has to be decoded.

    Thanks again,

    JimT


    JimT 2000

    Monday, April 15, 2013 7:35 PM