Generate UML class diagram from code files in Visual Studio

We can generate the UML class diagrams using the code files with the help of Visual Studio Ultimate version. Here I am going to show you, how we can do this using Visual Studio 2012 Ultimate version.

Assume that you have two classes called, Company and Employee

UML class diagram solution explorer

In order to create the URM class diagram from these two classes, go to ‘Architecture’ menu and click on ‘New Diagram…
Create UML diagram


It will launch another dialog called, Add New Diagram. Select ‘UML Class Diagram’ from the templates section, name your class diagram project and click on OK button.

Add UML class diagram

And then select ‘Modeling Project’ and give name for the project, click on OK

UML Modeling project

Now you will see one more new project in your solution explorer and UML class design surface window

UML class diagram project

Open the ‘Architecture Explorer’ from Architecture -> Windows -> Architecture Explorer

UML architecture explorer


  • You will get to see the ‘Class View’ and ‘Solution View’ in architecture explorer in first column.
  • On selection of class view, names spaces will display in second column.
  • On selection of namespace, all the types from the namespace will display in third column.
  • On selection of type, all the members from the type will display in fourth column

Architecture explorer window

Drag the namespaces or types from architecture explorer to UML class design surface. I have drag and dropped both Company and Employee objects to UML class design surface as shown below,

UML class design surface

From the above picture, you can identify that class members are marked with some special characters. Where,
- represents private members,
+ represents public members,
# represents protected members and
~ represents internal members

From here you can perform the UML operations by right-click on either class or class member -> Add,

UML class diagram

That’s it! UML class diagrams which are generated from your code are ready to use in Visual Studio. Hope this helps!

If you have any questions, please feel free to ask me from the comment box below.

2 comments:

  1. This information is impressive; I am inspired with your post writing style & how continuously you describe this topic. After reading your post, thanks for taking the time to discuss this, I feel happy about it and I love learning more about this topic.
    dot net training institutes in chennai|dotnet training in chennai

    ReplyDelete

Powered by Blogger.