这什么都没做,只是导致了对否则不必要的强制转换的需求(或者更确切地说,导致我拉下代码库并自己进行更改)。有这样做的理由吗?
引用:
Source on Codeplex
Blog posting with source
编辑
这是一个例子:
DoCommand = new RelayCommand<AsyncCallback>((callBack) =>
{
Console.WriteLine("In the Action<AsyncCallback>");
SomeAsyncFunction((async_result) =>
{
Console.WriteLine("In the AsyncCallback");
callBack.Invoke(new MyAsyncResult(true));
});
});
DoCommand.Execute((iasyncresult) => Console.WriteLine(iasyncresult.IsCompleted));
//Where MyAsyncResult is a class implement IAsyncResult that sets IsCompleted in the constructor
// This will cause the "cannot cast lambda as object" error
最佳答案
您的错误是由于lambda无法作为object
传递的。而是尝试:
AsyncCallback callback = (iasyncresult) => Console.WriteLine(iasyncresult.IsCompleted);
DoCommand.Execute(callback);
关于c# - 为什么RelayCommand <T> .Execute接受一个对象而不是T?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6296396/