Reputation: 24088
Is it a good idea to use "system namespaces" in my class libraries?
Sample:
namespace System.Web {
public static class RequestExtensions {
public static bool IsPost(this HttpRequest r) {
return string.Compare(r.HttpMethod, "POST", StringComparison.OrdinalIgnoreCase) == 0;
}
}
}
The advantage: no need to include additional uses-clauses (especially for extension methods), so all becomes available straight after adding reference to the library.
The best sample is NUnitEx project (which uses NUnit's namespace).
Disadvantages: potential name conflicts.
Upvotes: 4
Views: 1579
Reputation: 108985
The design guidelines talk about namespace naming:
The general format for a namespace name is as follows:
<Company>.(<Product>|<Technology>)[.<Feature>][.<Subnamespace>]
For example, Microsoft.WindowsMobile.DirectX.
Do prefix namespace names with a company name to prevent namespaces from different companies from having the same name and prefix.
There is no scope for reusing System
or Microsoft
here.
Upvotes: 4
Reputation: 32960
I have to second everyone else who says its a BAD idea. Namespaces are an organizational tool, on many levels. Not only do they allow you to reuse identifiers for your own purposes without conflicting with other companies, they also allow different companies to isolate their product from your's or anyone else's. Putting code into the System namespace can be very confusing for the people who use your types.
Additionally, people know that anything in a System namespace is good, solid, tested, community vetted, thoroughly documented code that came from Microsoft. Thats a pretty important set of factors to live up to...by sticking your code in the same namespace, not only are you claiming your code is that good, but you have to live up to it.
Upvotes: 15
Reputation: 50712
I think it is not good idea, because may be Microsoft will decide to create RequestExtensions class in the next versions of framework, It is always good practice to start namespace with your company name to prevent name conflicts
Upvotes: 2
Reputation: 10670
Using a System-based namespace can make it harder for someone to pick up your code and figure out what it's doing. For instance, if I pick up new C#, I often end up Googling things like "System.Web.xyz" when I don't know something.
In this case, I probably wouldn't know that "System.Web.RequestExtensions" wasn't a real member of the System.Web namespace, so I'd get stuck looking for a class that doesn't exist.
So basically, my view is that you need to document it really well or find another namespace.
Upvotes: 0
Reputation: 55072
Very very bad. It's confusing, and you should only do it if you absolutely have to (there are some cases when it's needed).
Only ever do it when it's 100% required, don't ever do it just for 'convenience'.
Upvotes: 3