I’m working through Josh Smith’s CommandSink Example and the base.Executed += (s, e) =>... structures are throwing me, can someone help make this crystal clear?
what I understand:
- base.CanExecute is the event on the inherited class CommandBinding
- the += is adding a delegate to that event
- the delegate is the anonymous function which follows that line
what I don’t understand:
- is (s,e) is the signature of that function?
- where is the variable s used?
Here is the code in context:
public class CommandSinkBinding : CommandBinding { #region CommandSink [instance property] ICommandSink _commandSink; public ICommandSink CommandSink { get { return _commandSink; } set { if (value == null) throw new ArgumentNullException('Cannot set CommandSink to null.'); if (_commandSink != null) throw new InvalidOperationException('Cannot set CommandSink more than once.'); _commandSink = value; base.CanExecute += (s, e) => { bool handled; e.CanExecute = _commandSink.CanExecuteCommand(e.Command, e.Parameter, out handled); e.Handled = handled; }; base.Executed += (s, e) => { bool handled; _commandSink.ExecuteCommand(e.Command, e.Parameter, out handled); e.Handled = handled; }; } } ...
(s, e)is the Method Parameter Signature for the event handler (in this case the anoymous method that’s defined)think
(object Sender, EventArgs e)The
sparameter just isn’t being used in the rest of the method which is fine. It has to be there to match the expected signatureis the equivalent of doing