我正在研究Josh Smith 的 CommandSink 示例,base.Executed += (s, e) =>...
结构让我很困惑,有人能帮我弄清楚吗?
我的理解:
- base.CanExecute 是继承类 CommandBinding 上的事件
- += 正在向该事件添加委托
- 委托是遵循该行的匿名函数
我不明白的是:
- (s,e) 是该函数的签名吗?
- 变量 s 在哪里使用?
这是上下文中的代码:
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;
};
}
}
...