Pass reflected method as parameter to another reflected method as delegate

234 views Asked by At

I have a function with a signature like so

private void FunkA(string eventName, Action action) {}
private void FunkB() {}

that I obtain though reflection. The value for action is also obtained through reflection so in my code I end up having to find a way to pass a 'MethodInfo' as a parameter into an invoke.

MethodInfo miForFunkA;
MethodInfo miForFunkB;

miForFunkA.Invoke(sourceOfFunkA, new [] {
    methodInfo.Name,
    Delegate.CreateDelegate(typeof(Action), miForFunkB)
});

The issue is I cant create a parameter list that has string and delegate types. How should this be passed?

1

There are 1 answers

1
Peter Duniho On BEST ANSWER

You should be to specify the array type explicitly:

miForFunkA.Invoke(sourceOfFunkA, new object[] {
    methodInfo.Name,
    Delegate.CreateDelegate(typeof(Action), miForFunkB)
});

If that doesn't address your question, you should edit your question so that it's clearer about what you're trying to do, declarations of all variables involved, what code you have now, what it does, and how that's different from what you want to do.