好吧!这已经在几个小时里给我强调了。c#接口实现异步等待
我使用所提供的组件有一个接口,我需要实现
public interface ICustomInterface
{
CustomType DoSomething(string name);
}
在我的代码我这样做:
public class MyClass: ICustomInterface
{
public MyClass()
{
}
// now I should implement the interface like this
public CustomType DoSomething(string name)
{
CustomType nType = new CustomType();
// do some work
return nType;
}
}
到目前为止好,但在我执行MyClass I中的接口需要使用async await
因此实现应该是这样的:
public class MyClass: ICustomInterface
{
public MyClass()
{
}
// now I should implement the interface like this
public async Task<CustomType> DoSomething(string name)
{
CustomType nType = new CustomType();
await CallSomeMethodAsync();
// do some extra work
return nType;
}
}
当然,这不起作用,因为它抱怨接口没有实现。
是否有一种方法来覆盖接受异步等待的接口实现?我不能修改提供的组件。
你不能那样做。 – SLaks 2015-04-01 19:44:59
寻找答案:http://stackoverflow.com/questions/13573516/interfaces-and-async-methods – maximdumont 2015-04-01 19:45:10