Hi folks,
I have a strategic question for my C#-project. I want to implement a plugin-concept and now struggling with the best way for the plugins to manipulate the data of the main project.
At first I created a "Master" PlugIn Project that defines the Interface for the plugins and an attribute to identify a class as a pluginclass when I load it in my main project.
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
public sealed class GraphViewerPlugInAttribute : Attribute
{
}
public interface IGraphViewerPlugIn
{
Panel GetRightSidePanel();
string Name();
}
This project is then referenced in the main project and the pluginclasses. The pluginclass implements the interface ...
[GraphViewerPlugIn]
public class myTestPlugIn : IGraphViewerPlugIn
{
public Panel GetRightSidePanel()
{
Panel myPanel = new Panel();
myPanel.BackColor = System.Drawing.Color.Red;
return myPanel;
}
public string Name()
{
return "TestPlugIn";
}
}
... and the main project loads all plugins that are stored in a certain directory.
This works quite well so far, I can get the special Panel from the PlugIn, but now I want to manipulate data of the main project from within the PlugIn. What would be the best way to do that? I have some kind of data-container-class that is defined in the "Master Plugin Project" in mind. The plugin puts the data into that container and the main project will be recognized by an event that the data has changed and can now look what data has changed and then apply the changes. Is that the right direction, what do I have to consider and which techniques (i.e. events, static classes ...) shall I use to implement that?
Thanks in advance, Frank