0

I am developing a project.

In my project, there will be embedded plugins and 3rd party plugins installed later.

I want to collect the plugins in a list with an attribute.

Plugins that will be embedded in the project and plugins that I load from the dll will be registered with the RegisterPlugin attribute in the list and then I will run them.

Draft Code:

public class InternalPlugin {
[RegisterPlugin ("abc")]
public void PluginAbc (string arg1, string arg2, string arg3) {
// Register a plugin without call function
    }
}

plugin123.dll

public class ExternalPlugin {
[RegisterPlugin ("abc")]
public void PluginAbc (string arg1, string arg2, string arg3) {
// Register a plugin without call function
    }
}

Attribute:

public class RegisterPlugin: Attribute {

public RegisterPlugin (string pattern) {
// Add function the array or list
    }

}

The function the data comes from:

public class DataClass {
    public void OnData (string data) (
        if (data = "abc") {
            // Find and invoke the function matching the pattern.
        }
}
}

I have no idea how to register them without running functions

Help me

Başar G.
  • 71
  • 5
  • 1
    plugin architecture usually revolves around the idea that a class implements a specific interface. For example `ISpecialPlugin`, then you'd just search for all classes that implement that interface. you can do it with class attributes as well, but you want your plugins to usually implement a specific interface so you can call to them in an abstract way. – Andy Mar 15 '21 at 23:01
  • 1
    If you really want to use attributes, look [at this](https://stackoverflow.com/questions/720157/finding-all-classes-with-a-particular-attribute). – Andy Mar 15 '21 at 23:03
  • Can we find the class according to the data and run the function with Interface? – Başar G. Mar 16 '21 at 17:15
  • sure, you could use a combination of both as well. – Andy Mar 16 '21 at 17:27

0 Answers0