Solved

Organizing a C# class library

Posted on 2009-05-11
3
819 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 63

Accepted Solution

by:
Fernando Soto earned 500 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Vb.net dynamic formulas in runtime 11 75
Media.Imaging 1 18
Video Player 2017 5 25
Keyboard 2 34
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

803 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