vendredi 20 novembre 2020

Convert the interface implementation object from one namespace to another since both are having the same interface but different namespace

Is there way to convert the interface implementation object from one namespace to another since both are having the same interface but only the namespace is differing?

Use case is like below

namespace namespaceA
{
Public Interface IInterface
{
Method1();
Method2();
}
}

namespace namespaceB
{
Public Interface IInterface
{
Method1();
Method2();
}
}

We get two kind of objects.

namespaceA.IInterface object - new implementation

namespaceB.IInterface object. - exists as a part of legacy implementation.

We wanted to handle only one object in the code i.e. namespaceA.IInterface object, based on the new implementation. But due to legacy implementation we get namespaceB.IInterface object also. But we don’t want to any specific handling for legacy object and we wanted to handle in the same way as new object and implementation.

So if we get an namespaceB.IInterface object, is there way to convert/cast it to namespaceA.IInterface object provided that interface definitions are same but only exists in a different namespace?

So the code need not worry only about the handling of legacy object.

Aucun commentaire:

Enregistrer un commentaire