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

Posted on 2005-04-28
Last Modified: 2012-06-27
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
    - {} 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.


Question by:kenshaw
    1 Comment
    LVL 9

    Accepted Solution

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


    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Suggested Solutions

    In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
    This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now