Accepting callbacks of arbitrary type
I'm trying to implement a JsonRpc client class in C# which executes a
given method / delegate / callback whenever the JsonRpc is responded (to
explain why I need the thing I'm going to ask).
To this end I want a method to register a callback of arbitrary type
(arbitrary argument list). This callback will be called / evaluated
whenever the response arrives. This means that at registration time
whatever the callback might be it is accepted and it's at execution time
which its type might cause an exception, once it is checked with
response's type.
I've seen codes implementing a similar concept like this:
//Defining a delegate based on a method signature
Delegate d = Delegate.CreateDelegate(delegate_type, context, methodInfo);
//Executing the delegate when response arrives
d.DynamicInvoke(parameters);
If I'm to implement the same, all I need to do is to accept an argument of
type Delegate for registering a callback. But this won't do for me since I
want it to be much easier to register a callback than creating its
Delegate (it takes a dozen of lines to come up with a Delegate of a
method).
At last here goes my question:
How would you implement registering a callback of arbitrary type in C#?
No comments:
Post a Comment