I have a data driven mapping application where I need to implement custom functions as plugins. The name of the custom method that I need to execute will also be in the mapping data. I know that I can call the method using the invoke command; but, how can I ensure that each method has the appropriate signature?
First of all I don't think you should allow arbitrary names for the overridden methods - just define an interface and keep it simple.
You could define an interface with a method that returns a delegate to the method that does the work.
Otherwise, you will just have to use reflection to get the MethodInfo for the mapped method and check at runtime that it hasd the correct signature.
Typically, when developing a plugin architecture, you define an interface with the methods that you will invoke on the plugin. The plugin is required to implement the interface. When you load it you cast it as the interface (if it doesn't implement it, this will fail) and use it in your code as the interface. If the behavior of the plugin is more generic, you simply define your interface more generically, for example using configuration to establish the plugin's parameters and then using a simple method without arguments to invoke the plugin's functionality. I think you'll find it easier to work with a pre-defined interface and it shouldn't limit you too much.
You will have to use reflection.
You will first have to call the GetMethod() method in order to get the MethodInfo object for the method in question.
Then you need to use the .GetParameters()
method to get hold of the parameters to the method, then you need to compare those against what you expect the method to have.