C#8.0中实现class时如何保留部分接口方法的默认实现?

How to retain some of the interface methods' default implementations in the implementing class in C# 8.0?

人们会认为在 C# 8.0 中您应该能够执行以下操作(根据 this (1st snippet)):

public interface IRestApiClient : IRestClient
{
    ...
    Task<T> PostPrivateAsync<T>(string action, OrderedDictionary<string, object> parameters = null, DeserializeCustom<T> deserializer = null)
    {
        return QueryPrivateAsync(Method.POST, action, parameters, deserializer);
    }
    ...
}

public class SpecificClient : ExchangeClient, IRestApiClient, IRestHtmlClient, ISeleniumClient, IWebSocketClient
{

}

上面的例子无法编译,因为接口成员需要显式和完整地实现(包括提供默认逻辑的方法)

所以人们会认为以下应该有效:

public interface IRestApiClient : IRestClient
{
    ...
    Task<T> PostPrivateAsync<T>(string action, OrderedDictionary<string, object> parameters = null, DeserializeCustom<T> deserializer = null)
    {
        return QueryPrivateAsync(Method.POST, action, parameters, deserializer);
    }
    ...
}

public class SpecificClient : ExchangeClient, IRestApiClient, IRestHtmlClient, ISeleniumClient, IWebSocketClient
{
    ...
    public async Task<T> PostPrivateAsync<T>(string action, OrderedDictionary<string, object> parameters = null, DeserializeCustom<T> deserializer = null) 
        => await ((IRestApiClient) this).PostPrivateAsync(action, parameters, deserializer);
    ...
}

不,看起来这个方法是递归的(尽管向上转换)并且会导致我们最喜欢的 Stack Overflow 异常。

所以我的问题是(从我可以更改示例中的设计这一事实中抽象出来),有没有一种方法可以保持特定方法默认的实现,最好不必诉诸 hacky 或 Static Helper扩展方法?我可以在接口和 class 中调用静态扩展方法,但这有点违背了此功能的目的。

// 编辑

我必须承认这让我感到困惑,而且我似乎遗漏了一些对其他人来说很明显的关键内容。我没有提供其他信息,因为我认为我的问题不是特定于代码的。让我们看一下这个简单的例子(取自我在 post 开头链接的网站):

根据@Panagiotis Kanavos评论:No, default members don't need to be implemented (...)我截图的应该不是真的。 sb可以赐教吗?

// 编辑 2

如您所见,我使用 C# 8.0 正确定位了 .NET CORE 3.0

错误:

Interface method cannot declare a body
Interface member 'void CryptoBotCoreMVC.IDefaultInterfaceMethod.DefaultMethod()' is not implemented

回答评论中的问题:我没有在 .csproj 文件中明确指定 LangVersion

// 编辑 3

问题出在 ReSharper 上,请参阅:

我的评论已经被删除了,大概是被答案的主人删除了,所以我把它写在这里:线索是实际上没有错误号,但编译被阻止了。原来,在ReSharper中出现这些错误时,有一个选项可以阻止编译。

看来这最终可能是重复的,但得出这个结论是一段漫长的旅程:)。

问题由ReSharper引起,参考:
https://youtrack.jetbrains.com/issue/RSRP-474628
看来问题将在版本 v2019.3 中得到解决,我们目前有 v2019.2.3。您可以设置 ReSharper 根据问题的严重程度阻止编译,解决方法是暂时禁用此功能。