P
P
Peter2018-10-26 12:46:58
C++ / C#
Peter, 2018-10-26 12:46:58

Change of interface implementation without project recompilation. How to implement?

Good afternoon. How can you replace the implementation of the functionality in the finished program?
I'll give you an example. I have an interface:

public interface IMessage
    {
        string GetMessage();
    }

There is a class that implements it:
public class Message : IMessage
    {
        public string GetMessage()
        {
            return "Hello From Message Class";
        }
    }

There is a form that creates a class variable and displays the result of the method in a MessageBox:
public partial class Form1 : Form
    {
        private readonly IMessage m;

        public Form1()
        {
            InitializeComponent();
            m = new Message();
        }

        private void Clickbtn_Click(object sender, EventArgs e)
        {
            MessageBox.Show(m.GetMessage());
        }
    }

I'm interested in the following, for example, I have a class that implements the interface will be in a separate dll library.
And I wanted to implement the interface differently. And that I could just create a new dll library and put it in the program folder. Is it possible? It turns out that I need something like creating plugins. What technology can be used to do this?
Thanks in advance for your replies.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
freeExec, 2018-10-26
@Morpheus_God

Through reflection. Load your assembly, look for classes that implement the interface you need and use them.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question