c# - How to document old value vs new value in generic function callback -


i have generic callback function notify listeners when value has changed:

public func<t, t, task> valuechangedasync { get; set; } 

where first t should old value , second t should new value.

i use callback this:

await valuechangedasync(old, newvalue); 

can make users of function aware of t old value , new value? when using callback gets implemented default:

private task valuechangedasync(string s, string s1) {     throw new notimplementedexception(); } 

i "s" named "oldvalue" , "s1" named "newvalue" or such.

you events , custom delegate type, delegate type documentation can indicate old value , new value parts. example:

// want non-void return type, we're not following event conventions // anyway... might have 3 parameters... public delegate task valuechangedhandler<t>(object source, t oldvalue, t newvalue); 

then:

public event valuechangedhandler<string> valuechanged; 

invoke as:

valuechangedhandler<string> handler = valuechanged; if (handler != null) {     var allhandlers = handler.getinvocationlist();     foreach (valuechangedhandler<string> individualhandler in allhandlers)     {         await individualhandler(this, oldvalue, newvalue);     } } 

Comments

Popular posts from this blog

php - render data via PDO::FETCH_FUNC vs loop -

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

The canvas has been tainted by cross-origin data in chrome only -