.NET Multiple Namespaces for single class

Viewed 30274

Is it possible to have a single class reside within two name-spaces and how can I do this?

To clarify: We have a class library (let say root namespace is classLib1), which has grown over time (more classes) and I want to logically group classes into different namespaces. However some of the older classes need to be grouped into these new namespaces (e.g classLib1.section1) and doing so will break legacy code in other assemblys that use this class library. So I want to be able to refer to a class using both name-spaces until we can phase the old ones out.

I can't find any information on this, which suggests there is a reason that people would not want to do this!?!

3 Answers

Type Forwarding was introduced in .net 2.0, which means you can use the TypeForwardedToAttribute attribute to indicate that a type which was originally present in AssemblyX is now to be found in AssemblyY.

I'm fairly sure this is only appropriate/applicable if you're separating out into multiple assemblies, but is worth knowing even if not.

Related