0

From what I know, you still need to instantiate the "body" of an interface in order to run correctly. For example, if you have an interface that looks like this:

public interface IResponse
{
    string GetResponse();
}

and the method calling the interface like so:

public TestCall(IResponse r)
{
    MessageBox.Show(r.GetResponse());
}

so when you call the method, the parameter has to be "instantiated" at some point, I can not just pass in an empty IResponse.

Whether it's in the Main Program or another class, it does not matter.

But what if I do NOT know the name of the inherited class before compiling?

Such as, I made 2 extensions dll both inherited from IResponse, for simplicity sack let's just call it A:IResponse and B:Iresponse, and user A decides to plug in A, user B decides to plug in B?

I can't do IResponse A = new A(); since A does not exist in user B's app, and vice versa.

So how can I make a foolproof way to instantiate whichever dll the users had chosen to plug in?

Much appreciated!

Noob002
  • 38
  • 5
  • basically your question is how to load a class from a DLL at runtime? – user253751 May 03 '22 at 09:34
  • It's not your job to do `new A` - you instead write code that finds anything that implements IResponse and creates an instance of it; it doesn't matter what it is. In essence, perhaps something reflective that "load all types from all DLLs in plugins folder, foreach type loaded, does type implement IResponse? yes, great, create instance of it and pass to TestCall" – Caius Jard May 03 '22 at 09:35
  • @user253751 To put it simply, yes. Could you help me? Much appreciated! – Noob002 May 03 '22 at 09:35
  • @CaiusJard Could you please be so kind as to give me an example? Much appreciated! – Noob002 May 03 '22 at 09:36
  • @user253751 Let me check it out, thank you very much for your help. – Noob002 May 03 '22 at 09:38

0 Answers0