C# 中的条件 Class 继承

Conditional Class inheritance in C#

好的,所以我正在为 Windows 8.1 Universal 开发一个应用程序,phone 上有一些 PC 平台上不存在的 API。问题是如果当前平台是 windows phone,我正在尝试有条件地继承 class。这是我的代码片段(不起作用)

    public class Client : IDisposable, IClient
#if WINDOWS_PHONE_APP
        , IWebAuthenticationContinuable
#endif
    {
#if WINDOWS_PHONE_APP
        void ContinueWebAuthentication(WebAuthenticationBrokerContinuationEventArgs args) { }
#endif

        public void DoStuff()
        {

        }

        public void Dispose()
        {

        }
    }

每当我尝试在我的视图模型中创建此 class 的新实例时,我都会收到以下错误: 无法创建 'App87.ViewModels.MainViewModel' 类型的实例 [行:9 位置:27]

第 9 行是我的构造函数,它只创建一个新的客户端实例 class。

尝试了您的确切代码,只有一件事不起作用:ContinueWebAuthentication 应该标记为 public,因为它是从接口继承的:

public interface IClient { }

#if WINDOWS_PHONE_APP
public interface IWebAuthenticationContinuable
{
    void ContinueWebAuthentication(WebAuthenticationBrokerContinuationEventArgs args);
}
#endif

public class Client : IDisposable, IClient
#if WINDOWS_PHONE_APP
    , IWebAuthenticationContinuable
#endif
{
#if WINDOWS_PHONE_APP
    public void ContinueWebAuthentication(WebAuthenticationBrokerContinuationEventArgs args) { }
#endif

    public void DoStuff()
    {

    }

    public void Dispose()
    {

    }
}