[Solved] C# Is there a way of implementing interfaces for classes from dlls?


Is there a way of doing this class implementing the interface below dynamically?

Short Answer: NO

If the dll is a 3rd party library then there is nothing you can do to modify that class as you have no control over it.

You could however create your own classes and abstraction to encapsulate the 3rd party dependency.

You create your desired interface

public interface IComunicator {
    void Execute();
}

And either using encapsulation

public class MyCommunicator : ICommunicator {
    private readonly Communicator communicator = new communicator();

    public void Execute() {
        communicator.Execute();
    }
}

or inheritance (if the class is not sealed)

public class MyCommunicator : Communicator, ICommunicator {

}

This way the property below

public IComunicator Comunicator{ get; set; }

Will be able to understand this assignment

obj.Comunicator = new MyComunicator();

0

solved C# Is there a way of implementing interfaces for classes from dlls?