Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Interface implementation has an extra argument in the function

Tags:

c#

.net

wpf

Here is the definition of a member of ICommand : http://msdn.microsoft.com/en-us/library/system.windows.input.icommand.execute.aspx

The signature is:

 
void Execute(
    Object parameter
)

It is implemented by RoutedCommand with the following signature ( http://msdn.microsoft.com/en-us/library/system.windows.input.routedcommand.execute.aspx ) :


public void Execute(
    Object parameter,
    IInputElement target
)

How can RoutedCommand Implement ICommand with an extra argument (IInputElement) in a member function?

like image 543
basarat Avatar asked Dec 21 '22 15:12

basarat


1 Answers

It uses explicit interface implementation to "hide" the ICommand.Execute method that takes a single parameter. The Execute method that takes two parameters is not an implementation of ICommand.Execute.

public class RoutedCommand : ICommand
{
    public void Execute(object parameter, IInputElement target)
    {
        // ...
    }

    // explicit interface implementation of ICommand.Execute
    void ICommand.Execute(object parameter)
    {
        // ...
    }
}
like image 187
LukeH Avatar answered Mar 07 '23 09:03

LukeH