Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio 2010/2012/2013, Class Diagram: how to show interface as base class, not as "lillypop"?

Since the interface is already on the diagram I would like to show inheritance reference explicitly. But I can't find how...

enter image description here

like image 586
Roman Pokrovskij Avatar asked May 11 '12 22:05

Roman Pokrovskij


1 Answers

There is a bug in VS 2005 up to 2012 that won't allow it to work. I have a work arround that might trick it into drawing the inheritance for interfaces. Say your interface is called IMyInterface. You have to replace it with an abstract class implementing that interface and use it instead of your interface. The code would make use of the conditional compilation and will look like this:

//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

That's likely to show it as you wish. In your case IMyInterface will become IMedicine.

like image 97
dmihailescu Avatar answered Nov 10 '22 02:11

dmihailescu