Can someone explain this C # structure: base.Executed + = (s, e) =>

I work through the Josh Smith CommandSink Example and the structures base.Executed += (s, e) =>...throw me, can someone help make this crystal clear?

what i understand:

  • base.CanExecute is an event of the inherited class CommandBinding
  • + = adds a delegate to this event
  • delegate is an anonymous function that follows this line

What? I do not understand:

  • is (s, e) is the signature of this 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;
                    };
            }
        } 
        ...
+3
source share
4 answers

(s, e) is the signature of the method parameter for the event handler (in this case, a specific anonymous method)

think (object Sender, EventArgs e)

s , . ,

base.CanExecute += (s, e) =>
                    {
                        bool handled;
                        e.CanExecute = _commandSink.CanExecuteCommand(e.Command, e.Parameter, out handled);
                        e.Handled = handled;
                    };

base.CanExecute += new EventHandler(myMethod_CanExecute);

///....
protected void myMethod_CanExecute(object sender, EventArgs e)
{
    bool handled;
    e.CanExecute = _commandSink.CanExecuteCommand(e.Command, e.Parameter, out handled);
    e.Handled = handled;
};
+11

, (s, e) - . , (CommandBinding.CanExecute: http://msdn.microsoft.com/en-us/library/system.windows.input.commandbinding.canexecute.aspx).

s . , .NET. , , EventArgs ( , EventArgs). CanExecuteRoutedEventArgs ( - ).

+1

(s, e) , #. # , Executed - ExecutedRoutedEventHandler, void delegate(object, ExecutedRoutedEventArgs). (s, e) => { ... } , s , e ExecutedRoutedEventArgs, - (object, ExecutedRoutedEventArgs) void.

, s , , , , ExecutedRoutedEventHandler. : " , ". # , , .

+1
base.CanExecute += (s, e) =>
                {
                    bool handled;
                    e.CanExecute = _commandSink.CanExecuteCommand(e.Command, e.Parameter, out handled);
                    e.Handled = handled;
                };

, , Lambda # 3.

# 2 : -

    base.CanExecute += delegate(object s, EventArgs e)
                {
                    bool handled;
                    e.CanExecute = _commandSink.CanExecuteCommand(e.Command, e.Parameter, out handled);
                    e.Handled = handled;
                };

# 3 (s, e) , ( , CanExecute ).

The = > , .

+1

Source: https://habr.com/ru/post/1706794/


All Articles