Generating Class Diagrams for .Net Core | by Edson Moisinho | Apr, 2022

Class diagram generated in Visible Studio Code

UML Class Diagrams are a really nice option to doc your system, examine and perceive the relationships between the courses and plan refactorings and disseminate data contained in the group.

Though having class diagrams brings many advantages, producing them manually is a painful and arduous activity, thankfully, we are able to use instruments to generate them mechanically

The Visual Studio Class Designer is a superb and really versatile device to generate class diagrams, it permits drag and drops on a single or in a number of .cs information on to the diagram, and it mechanically syncs adjustments each within the .cs information or within the diagram.

As we are able to see, utilizing the Class Designer has many benefits however sadly, it doesn’t exist within the Visible Studio Code and even within the Visible Studio, it doesn’t help .Internet Core.

PlantUML is an open-source device that permits producing many forms of UML diagrams from plain textual content, it makes use of a selected language and you’ll be taught and begin creating your diagrams in many alternative editors.

Fortuitously exists many extensions and add-ons that mechanically generate PlantUML from supply code, within the subsequent part I’ll present the way to generate the PlantUML and the diagrams utilizing C#.Internet Core straight in Visible Studio Code.

In an effort to generate the diagrams, I’ll create a couple of elements like courses, interfaces, enum, private and non-private properties, constructors, and constants.

I’m creating these elements simply to exemplify how the producing diagram device works, so please don’t take note of the courses and their content material.

Base courses, interface, and enum:

Mammal, Canine, Cat courses and IHunt interface

Derived courses and folder construction:

Canine and Cat little one courses

We will generate the PlantUml from the code utilizing the PlantUml Diagram Generator device.

First, set up the device through Nuget Package deal operating the command dotnet device set up --global PlantUmlClassDiagramGenerator --version 1.2.4

Subsequent, execute the command to look the .cs information contained in the folders and generate the .puml information operating dotnet puml-gen Entities generatedPuml -dir -execludePaths bin,obj,Properties -createAssociation -AllInOne these command parameters are quite simple and could be checked on the tool documentation.

The command will generate a folder within the root with all of the .puml particular person information and the embody.puml file with placing all of them collectively.

Printing logs, producing the output folder with all particular person .puml information

Or you should use Visible Studio Code to generate the information with out customizing the era course of.

Visible Studio Code generates a diagram choice

To learn the PlantUML information we might want to use the vscode/plantuml extension, as soon as put in it would present some choices within the IDE for exporting .puml information to pictures.

To put in it, search the extension within the Visible Studio Code Market:

PlantUML extension for VSCode within the Market

Then, reload the IDE and choose the PlanUml: Export Workspace Diagramschoice. It’s going to open a dialog asking for the picture format you wish to use earlier than producing an output folder with all of the exported diagrams photos:

Export Workspace Diagrams choice
Diagram format choice

As we are able to see, it was generated an ./out folder with one diagram for every particular person class and a giant one with all of the courses collectively in a single single picture file.

Folder construction with all generated information and full courses diagram

There are various different choices to discover that I’m not protecting right here, you’ll be able to verify the instruments documentation and discover all the opposite out there options.

Keep in mind we don’t must restrict this solely to C# code, the PlantUML is an open-source initiative, so different implementations exist already to help it for different languages.

I hope this text may help you and your group to generate good and helpful class diagrams, thanks for studying, and see you subsequent time.

More Posts