【发布时间】:2015-04-01 19:41:47
【问题描述】:
好的!这已经让我紧张了几个小时。
我正在使用提供的程序集,该程序集具有我需要实现的接口
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 中的接口实现中,我需要使用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;
}
}
当然这不起作用,因为它抱怨接口 ICustomerInterface.DoSomething.... 没有实现。
有没有办法覆盖接受异步等待的接口实现?
我无法修改提供的程序集。
【问题讨论】:
标签: c# interface async-await