14

由於接口已經在圖上,我想明確地顯示繼承引用。但我怎麼也找不到......Visual Studio 2010/2012/2013,類圖:如何將界面顯示爲基類,而不是「lillypop」?

enter image description here

+2

我對此也很感興趣,但從[this]判斷(http://social.msdn.microsoft.com/Forums/da-DK/vsclassdesigner/thread/0866a2d5-ad19-4e5c-a05b-0912eb7f7a13)和其他線程是不可能的。即使在VS 2012 RC! – ieaglle

+2

即使在VS 2013中依然無法使用! - 「在類和它實現的接口之間增加顯示行的支持是高度請求的功能之一,它是我們未來版本列表的最重要的特徵之一」 - 2005年MS陳述:) - http://social.msdn.microsoft .COM /論壇/ EN-US/0866a2d5-ad19-4e5c-A05B-0912eb7f7a13 /出接口的實現?論壇= vsclassdesigner。 –

+0

我喜歡你在過去4年中一直在編輯這個問題,添加新的視覺工作室版本。 2015年呢?那裏有運氣嗎? –

回答

7

有在VS 2005至2012年的錯誤,不會允許它的工作。 我有一個工作週轉,可能欺騙它繪製接口的繼承。 假設你的接口叫做IMyInterface。您必須將其替換爲實現該接口的抽象類,並使用它來代替您的接口。該代碼將使用條件編譯,看起來像這樣:

 
//to generate class diagram, add 'CLSDIAGRAM' to the conditional symbols on the Build tab, 
// or add '#define CLSDIAGRAM' at the top of this file 
#if CLSDIAGRAM 
#warning CLSDIAGRAM is defined and this build should be used only in the context of class diagram generation 
//rename your interface by adding _ 
public interface IMyInterface_ 
{ 
    int MyProperty { get; } 
    void MyMethod(); 
} 
//this class will act as an interface in the class diagram ;) 
public abstract class IMyInterface : IMyInterface_ // tricks other code into using the class instead 
{ 
//fake implementation 
    public int MyProperty { 
     get { throw new NotImplementedException(); } 
    } 

    public void MyMethod() 
    { 
     throw new NotImplementedException(); 
    } 
} 
#else 
// this is the original interface 
public interface IMyInterface { 
    int MyProperty { get; } 
    void MyMethod(); 
} 
#endif 

這很可能會顯示它,如你所願。 在你的情況下IMyInterface將成爲IMedicine。

+0

謝謝你的回答。我當然會使用一些額外的代碼來使設計圖更具信息性,但是將它與條件編譯一起使用對我來說是新事物。 –

相關問題