How to: Create UML Class Diagrams from Code

In Visual Studio Ultimate, you can add C# classes or namespaces from Architecture Explorer or dependency graphs to a UML class diagram. You can also add C# classes from Solution Explorer.

The class or classes that you drag will appear on the diagram. Classes on which they are dependent will appear in UML Model Explorer. See How the Models Represent Types.

To add classes from program code to a UML model

  1. Open a C# project.

  2. Create a UML modeling project.

    See How to: Create UML Modeling Projects and Diagrams.

  3. Add a UML class diagram to the modeling project:

    On the Architecture menu, choose New Diagram. In the Add New Diagram dialog box, select UML Class Diagram.

  4. Open Architecture Explorer:

  5. Drag namespaces or types from Architecture Explorer to the UML class diagram surface.

You can also drag namespaces or types from dependency graphs. See Visualize Code Dependencies on Dependency Graphs. You can drag classes from Solution Explorer.

Note Note

The code and the diagram are not updated automatically. You can update the diagram to discuss change proposals without affecting your code. Subsequent changes in the code will not automatically affect the diagram unless you again drag the classes onto the diagram.

This feature might run more quickly after you install Windows Automation API 3.0.

To open the C# code associated with a UML class

  • Double-click a class shape, attribute, or operation on the UML class diagram.

    The source code appears.

Types that you explicitly move onto the diagram are represented directly in the model and on the diagram.

Types on which these explicit types depend are represented as placeholders in the model. Their details are not represented, and nor are their dependencies.

However, if you subsequently drag a placeholder type from Architecture Explorer or dependency graphs onto the diagram, the placeholder will be replaced by a full type.