Event handling C# / Registering a callback

Posted by Jeff Dahmer on Stack Overflow See other posts from Stack Overflow or by Jeff Dahmer
Published on 2010-04-01T04:32:17Z Indexed on 2010/04/01 4:43 UTC
Read the original article Hit count: 173

Filed under:
|
|
|

Events can only return void and recieve object sender/eventargs right?

If so then craptastic.... how can I pass a function pointer to another obj, like:

public bool ACallBackFunc(int n) 
{
    return n > 0;
}

public void RegisterCallback(Something s)
{
     s.GiveCallBack(this.ACallBackFunc);
}

Something::GiveCallBack(Action? funcPtr)

I tried using Action, but I need it to return some value and Actions can only return void. Also, we do not know what kind of a callback we will be recieving; it could return anything and have any params! Reflection will have to be used somehow I reckon.

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET