I am using reflection class to invoke some methods which are on the some other dll. And one of the methods' parameters are type of delegate.
And I want to invoke this methods by using reflection. So I need to pass function parameters as object array, but I could not find anything about how to convert delegate to object.
Thanks in advance
I think this blog post:
C# Reflection - Dealing with Remote Objects
answers your question perfectly.
Here's an example:
you can see a delegate as variable type "function". the delegate describes the parameters and return value for a matching function.
the above example allows 'Foo' to be used as a data type, the only allowed object that can be matched with a variable of type Foo data type is a method with the same signature so:
Once you have assigned a method to a delegate, you can invoke the method via the delegate:
A delegate is an object. Just create the expected delegate as you would normally, and pass it in the parameters array. Here is a rather contrived example:
Instances of delegates are objects, so this code works (C#3 style) :
Hope it helps !
Cédric