Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

One Class with two different Namespaces?

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.

like image 739
RichC Avatar asked Dec 17 '22 23:12

RichC


1 Answers

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
like image 90
Matt Hamsmith Avatar answered Jan 15 '23 17:01

Matt Hamsmith