"JJ" <ge***************@lycos.nl> schrieb
I'm writing a program that uses plugins to add some functionality. It
works
as follows:
A plugin is a user control with a method getCoordArray(decimal inX,
decimal
inY, decimal inZ) and a property System.Drawing.Size bestsize. To use the
plugin, I need to do the following:
1) import the dll as a reference.
1b) validate the dll: look for the method getCoordArray(decimal inX,
decimal
inY, decimal inZ) and a property System.Drawing.Size bestsize
2) adding the user control to a panel in my form (only if step 1b returns
true)
Of course I know how to do this at design time, but how can I do this at
runtime?
Hi Vincent,
use System.Reflection.
//load Assembly
Assembly assm = Assembly.LoadFrom(yourDll.dll);
//get your Control
Type t = assm.GetType("yourControl");
//check if method exists
MethodInfo mi = t.GetMethod("getCoordArray");
if (mi != null)
{
ParameterInfo[] pi = mi.GetParameters();
//evaluate ParameterInfos
//[...]
//check returnType
if (mi.ReturnType == typeof (System.Drawing.Size))
{
//Create an instance of your control
Control c = (Control) assm.CreateInstance("yourControl");
//Add the control to your form
yourForm.Controls.Add(c);
//further actions with Control c
}
}
Have a look at
http://msdn.microsoft.com/library/en...onOverview.asp
for further information.
Cheers
Arne Janning