views:

56

answers:

1

Hello all, I am trying create such a plugin architecture that;
IPlugin: an interface that all plugins must implement.
NormalPlugin: a normal plugin.
ComplexPlugin: a plugin which, beside implementing the base methods, has some custom methods.
HostApp: an app that knows what an IPlugin is.

currently the host app will have ComplexPlugin at compile-time and will load the NormalPlugin dynamically. That's because host needs to have definitions in ComplexPlugin so it can call it's custom methods.
1) Are there any better methods for achieving this? because adding some plugins as reference to the host app at compile-time looks a little lame to me.

2) I tried using:

public interface IPlugin
{
   object CallCustomMethod(string methodName, object[] parameters);
}
but still, if CallCustomMethod returns a complex type, the app will need to know that complex type to cast to. thanks in advance

A: 

If the the app never calls ComplexPlugIn's custom methods other than through your CallCustomMethod function, then it seems to me that you shouldn't ever need to cast to a ComplexPlugIn.

IPlugIn foo = (IPlugIn)myComplexObject.CallCustomMethod("GenerateNewComplexPlugIn", new object[] { 0 });
foo.CallCustomMethod("AnotherComplexMethod", null);

Andrew
thanks for the answer. my problem is about knowing the return type of CallCustomMethod. it may return a ComplexData class/struct which is defined in ComplexPlugin. I tried to write the same type ComplexData also in the host app. but when i try to cast it compiler says: "can't convert the type ComplexData to ComplexData" :)
Slantroph
This particular problem could be resolved by defining ComplexData in a separate class library and including a reference to this library in both HostApp and ComplexPlugIn. This would seem to make sense from the point-of-view of decoupling the plug-in from the host app, which would seem to be the whole purpose of using plug-ins.Without knowing the "big picture" it's difficult to say whether the overall approach is good or bad....
Andrew
thanks Andrew. your suggestion looks like the best solution for the problem.
Slantroph