You have several options. The easiest, in my opinion, is to create a common interface, something like IPlugin . Add this to your remote build and let your application validate it.
IPluginManager manager = this; // let this class implement IPluginManager Assembly assembly = Assembly.LoadFile(downloadedFilePath); foreach (Type type in assembly.GetTypes()) { foreach (Type interfaceType in type.FindInterfaces ( delegate(Type m, object filterCriteria) { return m.FullName == typeof(IPlugin).FullName; } , null ) ) { IPlugin plugin = (IPlugin)Activator.CreateInstance(interfaceType); plugin.Activate(manager); } }
IPlugin and IPluginManager :
public interface IPluginManager { void Foo(); } public interface IPlugin { void Activate(IPluginManager manager); }
This code loads the downloaded assembly saved in a file into downloadedFilePath . He then finds the classes that implement IPlugin and loads them.
From there it's all yours. You can use both interfaces to add functionality to plugins and application. A class that implements IPluginManager processes all messages from and to plugins.
If you donβt like to ride on your own, you can use the MEF ( Managed Extensibility Framework ).
source share