c# - How to make EndInvoke generic? -
in code raise events using begininvoke
, because each event has different eventargs
, code full of duplicate functions, like:
private void endasyncconnect(iasyncresult iar) { var ar = (system.runtime.remoting.messaging.asyncresult)iar; var invokedmethod = (eventhandler<infoargs>)ar.asyncdelegate; invokedmethod.endinvoke(iar); } private void endasyncreceived(iasyncresult iar) { var ar = (system.runtime.remoting.messaging.asyncresult)iar; var invokedmethod = (eventhandler<receivedargs>)ar.asyncdelegate; invokedmethod.endinvoke(iar); }
is there way make endasync function generic events?
if event delegate types eventhandler<t>
, should work:
void completioncallback<t>(iasyncresult iar) t : eventargs { var ar = (system.runtime.remoting.messaging.asyncresult)iar; var invokedmethod = (eventhandler<t>)ar.asyncdelegate; invokedmethod.endinvoke(iar); }