Is it possible to undo a C # namespace alias?

Not sure how to formulate this question, but here is the problem.

I have a namespace: my.foo.bar

In one of my classes, I accidentally named the namespace my.foo.bar

I want to fix the capitalization of the namespace so that everyone is on the same page, but this is a shared library, and I cannot afford to recompile all the programs using this.

So, is there something I can create that essentially redirects my.foo.bar to my.foo.bar ?

+7
source share
2 answers

Not globally. You can use namespace aliases , but only in client code. It looks like you may have to make a drastic change.

One way to do this if it is only one or two classes is to copy them from my.foo.Bar to my.foo.Bar , discount those that are in a bad namespace using the Deprecated attribute and slowly move clients to the correct ones .

If the class has no state, then the class in the my.foo.Bar namespace can delegate it to the my.foo.Bar namespace, as @JohnSaunders suggests, but only if using this class does not exclude the possibility of delegation (the whole method or property, this class type is not used for reflection, etc.).

+7
source

The best thing you can do is to take all the types in the name of the names with the wrong name and create their versions in the correct namespace. They may delegate the wrong version of the namespace.

+6
source

All Articles