Reputation: 7879
Is something like this possible?
Namespace Transaction, Document
Class Signer
Public Sub New()
'Do Work
End Sub
End Class
End Namespace
I basically want to be able to instantiate the Signer class from either Namespace. The reason is that I mistakenly set it up in the Transaction class and need to migrate it over to the Document class without breaking existing legacy code. I'd prefer to not have the same Signer class duplicated in both Namespaces if possible.
Upvotes: 4
Views: 1368
Reputation: 48949
What you need to do is create the class in separate namespaces so that you actually have two different classes declared. Mark the one in the Transaction
namespace as obsolete and have it act as a proxy to the real class that way you do not 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
Upvotes: 3
Reputation: 33143
A class can only belong to one namespace. The only other thing you can do is duplicate that class in another namespace. You should be able to refactor that code and change the namespace, visual studio will propogate those changes throughout your code.
Upvotes: 3
Reputation: 4036
I don't think you can do that. However, you CAN define the object in one namespace and then make a class of the same name in the other namespace that simply inherits the first class, like so:
Namespace Transaction
Class Signer
' Signer class implementation
End Class
End Namespace
Namespace Document
Class Signer
Inherits Transaction.Signer
End Class
End Namespace
Upvotes: 7