接口实现在函数中有一个额外的参数
本文关键字:参数 有一个 实现 函数 接口 | 更新日期: 2023-09-27 17:50:15
ICommand的成员定义:http://msdn.microsoft.com/en-us/library/system.windows.input.icommand.execute.aspx
签名是:
<>之前
void Execute(
Object parameter
)
之前由RoutedCommand使用以下签名(http://msdn.microsoft.com/en-us/library/system.windows.input.routedcommand.execute.aspx)实现:
<>之前
public void Execute(
Object parameter,
IInputElement target
)
之前RoutedCommand如何在成员函数中使用额外的参数(IInputElement)实现iccommand ?
它使用显式接口实现来"隐藏"接受单个参数的ICommand.Execute
方法。接受两个参数的Execute
方法不是 ICommand.Execute
的实现。
public class RoutedCommand : ICommand
{
public void Execute(object parameter, IInputElement target)
{
// ...
}
// explicit interface implementation of ICommand.Execute
void ICommand.Execute(object parameter)
{
// ...
}
}
iccommand . execute()接口方法显式实现。文档在这里