From this MSDN article, there are several ways to connect a delegate that uses reflection.
It seems the best way is with the CreateDelegate method:
Delegate d = Delegate.CreateDelegate(delegateType, targetObject, handlerMethodName);
Under normal circumstances, I would point to a handler method that resides in the targetObject class. But what if a delegate was created anonymously? Example:
public delegate void SelectedVehiclesCollectionDelegate(string query, List<Vehicles> list);
...
myObject.SelectedVehiclesCollection = (query, list) =>
{
};
There is no method in the definition of the class that the delegate refers to. I need to call this delegate, which is unknown at runtime, resulting in a list of items.Well, it looks like my terminology got the best of me. I did not seek to create a handler, but referred to what already happened (Thomas Petrichekβs answer still gives me some idea).