How to handle same class name in different namespaces?
The MS guidelines have the following to say:
Do not introduce generic type names such as Element, Node, Log, and Message. There is a very high probability it would lead to type name conflicts in common scenarios.
and
Do not give the same name to types in namespaces within a single application model.
I concur that it's probably a good idea to use BarcodeUtilities
and ErpUtilities
instead. (Unless the utility classes are not meant to be used by client code, in which case you could name them Utilities
and make them internal
.)
If i do that i will then need to specify the full namespace name before my static class in order to access it?
No, there is no need for that, though the details depend on the class that will use these types and the using
declarations it has.
If you only use one of the namespaces in the class, there is no ambiguity and you can go ahead and use the type.
If you use both of the namespaces, you will either have to fully qualify the usages, or use namespace/type aliases to disambiguate the types.
using ERPUtils = MyCompany.ERP.Utilities;
using BCUtils = MyCompany.Barcode.Utilities;
public void MyMethod()
{
var a = ERPUtils.Method();
var b = BCUtils.Method();
}
"Utilities" is not a very good name for a class, since it is far too generic. Therefore, I think you should rename both of them to something more informative.
There isn't any other way. You can make an aliases in using
directives:
using MC=MyCompany.ERP;
using MB=MyCompany.Barcode;
...
public void Test()
{
var a = MC.Utilities.Method();
var b = MB.Utilities.Method();
}
It's the simplest way to manage them.