Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is using System.* Namespaces on your own classes considered Bad Practice? [duplicate]

I have a class called ConfigurationElementCollection<T>

It's a generic implementation of System.Configuration.ConfigurationElementCollection

It's stored in our solutions', Project.Utility.dll but I've defined it as being part of the System.Configuration namespace

namespace System.Configuration
{
    [ConfigurationCollection(typeof(ConfigurationElement))]
    public class ConfigurationElementCollection<T> : 
        ConfigurationElementCollection where T : ConfigurationElement, new()
    {
       ...
    }
}

Is putting classes in the System.* namespaces considered bad practice when they aren't part of the System.* Base Class Libraries ?

On the face of it, it seems to make sense, as it keeps similar classes with similar functionality in the same place. However it could cause confusion for someone who didn't realise it was actually part of a non .net BCL as they wouldn't know where to go hunting for the reference.

like image 248
Eoin Campbell Avatar asked May 14 '11 17:05

Eoin Campbell


People also ask

Can a class have multiple namespaces?

Two classes with the same name can be created inside 2 different namespaces in a single program.

What are the two types of namespaces?

When creating a namespace, you must choose one of two namespace types: a stand-alone namespace or a domain-based namespace. In addition, if you choose a domain-based namespace, you must choose a namespace mode: Windows 2000 Server mode or Windows Server 2008 mode.

Should I use namespaces C#?

They're used especially to provide the C# compiler a context for all the named information in your program, such as variable names. Without namespaces, for example, you wouldn't be able to make a class named Console, as . NET already uses one in its System namespace.

What classes are in the System namespace?

The System namespace is the root namespace for fundamental types in . NET. This namespace includes classes that represent the base data types used by all applications, for example, Object (the root of the inheritance hierarchy), Byte, Char, Array, Int32, and String.


1 Answers

While your class is similar it is still not part of the BCL. I would not put it in System.* because of this. It will cause confusion especially when one goes to use it and they have System.* referenced and then get a nasty can't find message when they go to use your class.... :-)

like image 180
Kevin LaBranche Avatar answered Sep 21 '22 18:09

Kevin LaBranche