One class with two different namespaces?

Is this possible?

Namespace Transaction, Document Class Signer Public Sub New() 'Do Work End Sub End Class End Namespace 

Basically, I want to be able to instantiate the Signer class from any namespace. The reason is that I mistakenly installed it in the Transaction class and you need to transfer it to the Document class without breaking existing legacy code. I would prefer that the same Signer class not be duplicated in both namespaces, if possible.

+4
source share
3 answers

I do not think you can do this. However, you can define an object in one namespace, and then create a class with the same name in another namespace that simply inherits the first class, for example:

 Namespace Transaction Class Signer ' Signer class implementation End Class End Namespace Namespace Document Class Signer Inherits Transaction.Signer End Class End Namespace 
+6
source

A class can belong to only one namespace. The only thing you can do is duplicate this class in a different namespace. You should be able to reorganize this code and change the namespace; visual studio will propagate these changes in your code.

+2
source

What you need to do is create a class in different namespaces so that two different classes are actually declared. Mark one in the Transaction namespace as deprecated and make it a valid proxy for the real class so you don't duplicate the implementation.

 Namespace Transaction <Obsolete> _ Public Class Signer Private m_Implementation As Document.Signer Public Sub New() m_Implementation = new Document.Signer() End Public Sub DoSomething() m_Implementation.DoSomething() End Sub End Class End Namespace Namespace Document Public Class Signer Public Sub New() End Public Sub DoSomething() End Sub End Class End Namespace 
+2
source

Source: https://habr.com/ru/post/1315564/


All Articles