Plugins
-
How do you give a plugin access to all data and methods of the hosting application? Is it possible to set a plugins/interfaces method to respond to a windows event?
You don't give a plugin access to the data and methods of the hosting application. Your host communicates with the plugin (which is the opposite way around). Typically, your application will provide some interfaces which your plugin may or may not implement. For instance:
public interface IDataWrapper { object State{ get ; set ; } bool HasProcessed{ get; } } public interface IPlugin { void Start(); } public class MyPlugin : IPlugin, IDataWrapper { private object _state; private bool _isSuccessful = false; public object State { get { return _state; } set { _state = value; } } public bool HasProcessed { get { return _isSuccessful; } } // Do some processing with this... public void Start() { // Do something.... } }
Then, in your application you would load the plugin and do something like:
IPlugin plugin = LoadPlugin(...); IDataWrapper wrapped = plugin as IDataWrapper; if (wrapped != null) { wrapped.State = ...; } plugin.Start(); if (wrapped != null) { if (wrapped.HasProcessed) { ... } }
Deja View - the feeling that you've seen this post before.
-
How do you give a plugin access to all data and methods of the hosting application? Is it possible to set a plugins/interfaces method to respond to a windows event?
-
Download the code, compile it and run it through the excellent .NET Reflector (from Lutz Roeder). Reflector allows you to change the language target, so you can see what it would be in C#.
Deja View - the feeling that you've seen this post before.