我正在使用反射器进入Microsoft.Practices.Prism程序集,并为DelagateCommand的构造函数遇到以下定义:
public DelegateCommand(Action executeMethod, Func<bool> canExecuteMethod)
: base(action, func)
{
Action<object> action = null;
Func<object, bool> func = null;
if (action == null)
{
action = o => executeMethod();
}
if (func == null)
{
func = o => canExecuteMethod();
}
if ((executeMethod == null) || (canExecuteMethod == null))
{
throw new ArgumentNullException(
"executeMethod",
Resources.DelegateCommandDelegatesCannotBeNull);
}
}
Run Code Online (Sandbox Code Playgroud)
此代码无法编译,因为它: base(action, func)指向ctor中的前两个变量.
是否有可能复制这种行为?也许是通过使用匿名方法?
提前感谢您的意见.
Reflector IL用于此方法:
.method public hidebysig specialname rtspecialname instance void .ctor(class [mscorlib]System.Action executeMethod, class [mscorlib]System.Func`1<bool> canExecuteMethod) cil …Run Code Online (Sandbox Code Playgroud)