Share via

Create UML Class Diagrams from Code

To add C# classes from code to your UML class diagram in Visual Studio Ultimate, drag those classes or namespaces from Solution Explorer, dependency graphs, or Architecture Explorer to your UML class diagram.

Any classes on which they depend also 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. Add a UML class diagram to your solution:

    On the Architecture menu, choose New Diagram. In the Add New Diagram dialog box, select UML Class Diagram. A modeling project will be created, if you don’t already have one.

  3. Open Architecture Explorer:

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

    To see a type, expand Class View in the first column of Architecture Explorer, and then expand a namespace in the next column. You’ll see the types in the third column.

You can also drag namespaces or types from dependency graphs. See Map dependencies across your code on dependency graphs. You can drag classes from Solution Explorer.


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.

How the Model Represents Types

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.

See Also


UML Class Diagrams: Reference

Create UML Modeling Projects and Diagrams

Find code with Architecture Explorer