Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 426
  • Last Modified:

How do you make enum member of namespace like CommandType enum of SqlCommand in ADO.NET?

I want to use an enum to restrict the values that a property in one of my classes can take in a similar way to the way enums are used for sql CommandTypes.  Examples:

sqlCommand1.CommandType = System.Data.CommandType.StoredProcedure;
sqlCommand1.CommandType = System.Data.CommandType.TableDirect;
sqlCommand1.CommandType = System.Data.CommandType.Text;

So, I would like to have something similar such as:

myClass.DayofWeek = my

When I look at the object browser, I see a tree like this:

- system.data
   + {} System
    - {} System.Data
        + AcceptRejectRule
        + CommandBehaviour
        + CommandType
        + etc...

CommandType is a public sealed enum.  My question is:  the enum definition must still be defined in a class somewhere, even though I can't see that class in the object browser.  I tried to do the same thing with my own enum but when I look in the object browser, I can't make the enum look like it is a member of the namespace (as in System.Data.CommandType).  Instead, my enum shows as a member of a class.  For example,

- myAssembly
   - myNamespace
      - myClass
      - myClass.myEnum

I don't want to see the myClass.  I just want to see myEnum directly under myNamespace.


1 Solution
You can define enums outside of classes (i.e. immediately under the namespace).


Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now