Reputation: 5717
Ok! This is already stressing me for few hours.
I'm using a provided assembly that has an interface I need to implement
public interface ICustomInterface
{
CustomType DoSomething(string name);
}
in my code I do like this:
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;
}
}
So far so good but in my implementation of the interface in the MyClass I need to make use of async await
therefore the implementation should be like this:
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;
}
}
And of course this doesn't work because it complains the Interface ICustomerInterface.DoSomething....
is not implemented.
Is there a way to override the interface implementation that accepts async await?
I cannot modify the provided assembly.
Upvotes: 0
Views: 4288
Reputation: 203827
That's impossible. If the interface requires the operation to be computed synchronously, then the operation needs to be performed synchronously.
Upvotes: 7