Hi everybody!
I am kind of new to C# .Net and I am enjoying the learning process! Right now I am working on a project (just to learn) in which plug-ins are the main key.
I did the following till now which seems to work fine:
Interface:
namespace My.test
{
public interface IMyPlugin
{
bool Execute(string Id, Object param);
List<string> GetPluginIdList();
}
}
a test plug-in implementing IMyPlugin Interface:
using System;
..
..
using My.test;
namespace demoplg
{
public class SamplePlugIn: IMyPlugin
{
public bool Execute(string Id, object param)
{
MessageBox.Show(Id, "SamplePlugIn");
return false;
}
public List<string> GetPluginIdList()
{
List<string> result = new List<string>();
result.Add("test1");
result.Add("test2");
return result;
}
}
}
and in the main application (Host) I am using Reflections to load the Dll (assembly) and create an Instance of the plug-in.
try
{
Type[] types = PlugIn.GetTypes();
Type MyPlugInType = null;
foreach (Type libtype in types)
{
//check if it implements the IMyPlugin.
Type[] interfacelist = libtype.GetInterfaces();
foreach (Type lookupInf in interfacelist)
{
if (lookupInf.Name.Equals("IMyPlugin"))
{
MyPlugInType = libtype;
break;
}
}
if (MyPlugInType == null) continue;
IMyPlugin xplg = null;
ConstructorInfo ci = MyPlugInType.GetConstructor(new Type[] { });
xplg = ci.Invoke(null) as IMyPlugin;
return xplg;
}
return null;
}
catch
{
return null;
}
well, now what I want to have is, that a plug-in can have it's on configuration GUI, which I would like to add that in my Host (Main application) by calling something for example: xplg.RegisterPluginGUI();
Let say something in the form of a tree-view on the left side showing the name/description of the plug-in, and on the right side kind of a container where I can drop the UI of the plug-in on it.
can some one please give some advice how to achieve this?
Well, I've done something similar in Delphi which is not a very clean work ;-) Using WIN API to process the messages of a from inside a dll cached in the main form!!!
Thanks in advance! AK