自动类图生成
Github: orrest/PlantUmlClassDiagramGenerator Fork 自 pierre3/PlantUmlClassDiagramGenerator 项目。
Project Overview¶
PlantUmlClassDiagramGenerator is a tool that automatically generates PlantUML class diagrams from C# source code. The project provides multiple integration options to help developers quickly visualize C# code structure and relationships.
Core Features¶
The tool analyzes C# source code and generates standard PlantUML class diagrams, supporting:
- Type declarations: including class, struct, interface, enum, record types
- Type modifiers:
abstract,static,partial,sealedmodifiers - Member visibility:
public,private,protected,internalaccess modifiers - Relationship mapping: automatic identification of inheritance, implementation, and association relationships
Roslyn Source Generator¶
The most advanced approach: automatically generating class diagrams at compile time using a Source Generator.
This method uses compiler symbol information rather than syntax trees for more accurate code structure analysis.
Steps:¶
-
Install the NuGet package in the project you want to generate class diagrams from:
(If your class files are distributed across multiple projects, install the package in each one.)
-
In your project's
.csprojfile:<PropertyGroup> <DefineConstants>$(DefineConstants);GENERATE_PLANTUML</DefineConstants> </PropertyGroup> <ItemGroup> <CompilerVisibleProperty Include="PlantUmlGenerator_OutputDir" /> </ItemGroup> <PropertyGroup> <PlantUmlGenerator_OutputDir>$(SolutionDir)generated-uml</PlantUmlGenerator_OutputDir> </PropertyGroup>- The constant
GENERATE_PLANTUMLtriggers the generator. - If you have class diagrams across multiple projects, specify the same output folder so they can reference each other.
- The constant
-
Add the attribute in your
4. Build the project, and you'll see theAssemblyInformation.csor directly on classes:.pumlfiles in thePlantUmlGenerator_OutputDirfolder you specified.
See the original README.
What Is This Fork For?¶
- Added
reddress-darkblueas the default theme in the source generator library. - Specified the direction of the associations in the source generator:
- Implementations and inheritances are vertical
- Compositions, aggregations, and dependencies are horizontal
Note¶
- If the theme is not previewing correctly in VS Code, consider updating the PlantUML version.
- For the usage of VS extension and the dotnet CLI tool, see the original project.