Click here to Skip to main content
15,867,944 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I've written a plugin-based application, but the problem I've made it up to 2 plug-ins that run the input method list of Customers take

But I write the third plugin was just a customer.

The problem is that I've got a list of "Customer" interface "IAction" Run method considered and now I know how to plugin a "Customer" to send a third.

In general, I consider myself a structure for all plugins

How to create an appropriate structure for each plug-in principle?


C#
namespace PluginDatabase.Defention{
public interface IPlugin
{
    string Name { get; }


    List<IAction> Actions { get; }


}
}


C#
namespace PluginDatabase.Defention{
public interface IAction
{
    string Name { get; }


    void Run(List<Customer> customers);


}
}


C#
private void Form1_Load(object sender, EventArgs e){
int x = 250;
int y = 342;
var dlls = Directory.GetFiles(@"Plugins\", "*.dll");
foreach (var dll in dlls)
{


    var asmbli = Assembly.LoadFrom(dll);
    foreach (var typee in asmbli.GetTypes())
    {
        if (typee.GetInterface("IPlugin") != null)
        {
            var plugin = Activator.CreateInstance(typee) as IPlugin;



            foreach (var action in plugin.Actions)
            {

                var actionButton = new Button();
                actionButton.Text = action.Name;

                actionButton.Click += (ss, ee) =>
                {

                    action.Run(getCustomers());

                };
                actionButton.Location=new Point(x,y);
                actionButton.Size = new Size(100, 43);
                this.Controls.Add(actionButton);
                x-= 110;

            }
        }

    }


}}
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900