Solved

Organizing a C# class library

Posted on 2009-05-11
3
830 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
defining NULL or 0 10 51
Code works but breaks when I add one section 4 31
C# Get Current Exchange Rate from XE 9 18
aspx ascx, c# 7 21
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

696 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