Solved

Organizing a C# class library

Posted on 2009-05-11
3
801 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
Comment Utility
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
Comment Utility
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 62

Accepted Solution

by:
Fernando Soto earned 500 total points
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

771 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

11 Experts available now in Live!

Get 1:1 Help Now