簡體   English   中英

C#中的條件類繼承

[英]Conditional Class inheritance in C#

好吧,所以我正在為Windows 8.1 Universal開發一個應用程序,並且手機上有一些API在PC平台上不存在。 問題是,如果當前平台是Windows Phone,我將嘗試有條件地繼承類。 這是我的代碼的一部分(不起作用)

    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()
        {

        }
    }

每當我嘗試在視圖模型中創建此類的新實例時,都會出現以下錯誤:無法創建類型為'App87.ViewModels.MainViewModel'的實例[行:9位置:27]

第9行是我的構造函數,它僅創建Client類的新實例。

嘗試了確切的代碼,只有一件事不起作用: 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()
    {

    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM