Dynamically create delegates
March 20th, 2009
Recently I was facing a problem regarding delegates. I needed to dynamically create a delegate which “points to” a dynamically reflected method which is not static on a given type. The problem was, that at the time of the “inspection” of the type I had no instance of that type available. Normally delegates “pointing to” instances are said to be closed on a given instance therefore you need to have a concrete instance of the type available which the delegate can be bound to.
An example of a closed delegate is the following:
public delegate void MyDelegate(string parameter)
But what happens if you don’t have an instance of a given type present at the time of inspection and you want to dynamically create and later assign the delegate to a type?

