私はJosh Smith の CommandSink Exampleに取り組んでいますが、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;
};
}
}
...