Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Organizing a C# class library

Posted on 2009-05-11
3
Medium Priority
?
856 Views
Last Modified: 2012-05-06
How can a class library be organized, similar to Microsoft's libaries where classes are in a tree structure, i.e. namespace.class.subclass.subclass.method.
Classes in my current library are organized on an inheritance level, but I'd like to be use them as outlined above.
0
Comment
Question by:mtasking
3 Comments
 
LVL 7

Expert Comment

by:zwei
ID: 24357042
If you're wondering about how to organize your files in namespaces or how to name your namespaces, looking at big open-source projects usually works to get an idea of the structure.

The general rule for naming namespaces is to use the company name followed by the technology name and optionally the feature and design as follows:

CompanyName.TechnologyName[.Feature][.Design]

Prefixing namespace names with a company name or other well-established brand avoids the possibility of two published namespaces having the same name. Use a stable, recognized technology name at the second level of a hierarchical name.

The dot operator separates namespaces and/or classes, not classes and subclasses. If you have class B that extends class A you can't do
ClassA.ClassB
0
 
LVL 39

Expert Comment

by:abel
ID: 24357072
You can put on top of each class, or in fact, surrounding any class, a "namespace" statement (different from a "using" directive). It looks as follows:

however, the inheritance is not so visible when you use the object browser. Instead, the object browser (I assume that's what you are referring to), shows the assemblies, and the assemblies usually follow the names of the namespaces (though some assemblies contain multiple namespaces and vice versa).

namespace myNameSpace.mySubNamespace   // you are free of choosing names here
{
   class myClass
   {
 
 
        class childClass
        {
        }
   }
 
 
}

Open in new window

0
 
LVL 64

Accepted Solution

by:
Fernando Soto earned 2000 total points
ID: 24357125
Hi mtasking,;

To create a tree structure for your library you need to use a nested Namespace. See the below document.

From the Microsoft documentation: The namespace keyword is used to declare a scope. This namespace scope lets you organize code and gives you a way to create globally unique types.
http://msdn.microsoft.com/en-us/library/z2kcy19k(vs.80).aspx

Fernando
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Loops Section Overview
Suggested Courses

877 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