2012-04-17 24 views

回答

1

我加入存根/虛擬屬性類,模仿他們的整箱同行緊湊框架項目克服了這個問題,並且沒有任何預處理器指令。

+0

馬特謝謝你在盒子外面思考!這也是一個可行的解決方案。 – Tedford 2012-04-17 16:43:14

+0

@MattDavey對不起,我遲到了,但我不認爲這是一個值得推薦的解決方案(糾正我,如果我錯了)。 'ComVisibleAttribute'在PCL中不可用,但* *在大多數目標中可用。因此,無論何時您想在特定目標(例如.NET應用程序)中使用PCL,您都會遇到名稱衝突。我想你可以使用'TypeForwardedToAttribute'來解決這個問題,但是我自己沒有經驗。 – 2013-12-05 16:56:25

3

您可以在構建屬性中配置自己的預處理器符號。我不知道默認是否有任何特定的可移植類庫,但是在您的項目的每個配置中指定一個並不難。

// Shared source file 
[ComVisible(true)] 
public class Foo 
{ 
} 

// Dummy class in portable project -- exists only to facilitate compilation of the shared source file 
namespace System 
{ 
    [AttributeUsage(AttributeTarget.Class)] 
    public class ComVisibleAttribute : Attribute 
    { 
     public ComVisibleAttribue(bool visible) 
     { 
      // Dummy implementation 
     } 
    } 
} 

現在共享的源代碼文件將在兩個項目編譯沒有任何修改的代碼:

+0

感謝喬恩,我在尋找一個內置的,但這是有道理的,並節省了時間! – Tedford 2012-04-17 16:20:34

相關問題