SkillAgentSearch skills...

PlantUmlClassDiagramGenerator

This is a generator to create a class-diagram of PlantUML from the C# source code.

Install / Use

/learn @pierre3/PlantUmlClassDiagramGenerator
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

<div align="center"> <strong><a href="README.md">English</a> | <a href="README.zh-CN.md">简体中文</a></strong> </div>

PlantUmlClassDiagramGenerator

This is a generator to create a class-diagram of PlantUML from the C# source code.

README.md Version revision history

| Version | Commit | Comment | |---------| ------------------------------------------------------------ |--------------------------------------------------------------------------------------------------------------| | 1.2 | df40b74 | Add "-addPackageTags" option | | 1.1 | e73b4fe | Add "-excludeUmlBeginEndTags" option | | 1.0 | 70bb820 | Because the README.md for other languages is not always updated at the same time, a version number is needed |

Roslyn Source Generator

The class diagram is automatically generated by the Roslyn Source Generator. Details are provided in the link below.

Visual Studio Code Extension

.Net Core global tools

Nuget Gallery: https://www.nuget.org/packages/PlantUmlClassDiagramGenerator

Installation

Download and install the .NET 8.0 SDK or newer. Once installed, run the following command.

dotnet tool install --global PlantUmlClassDiagramGenerator

Usage

Run the "puml-gen" command.

puml-gen InputPath [OutputPath] [-dir] [-addPackageTags] [-public | -ignore IgnoreAccessibilities] [-excludePaths ExcludePathList] [-createAssociation]
  • InputPath: (Required) Sets a input source file or directory name.
  • OutputPath: (Optional) Sets a output file or directory name.
    If you omit this option, plantuml files are outputted to same directory as the input files.
  • -dir: (Optional) Specify when InputPath and OutputPath are directory names.
  • -addPackageTags: (Optional) If there is "-dir" tag, then program adds "package" tags and puts all relations in the end of include.puml
  • -public: (Optional) If specified, only public accessibility members are output.
  • -ignore: (Optional) Specify the accessibility of members to ignore, with a comma separated list.
  • -excludePaths: (Optional) Specify the exclude file and directory.
    Specifies a relative path from the "InputPath", with a comma separated list. To exclude multiple paths, which contain a specific folder name, preceed the name by "**/". Example: "**/bin"
  • -createAssociation: (Optional) Create object associations from references of fields and properites.
  • -allInOne: (Optional) Only if -dir is set: copy the output of all diagrams to file include.puml (this allows a PlanUMLServer to render it).
  • -attributeRequired: (Optional) When this switch is enabled, only types with "PlantUmlDiagramAttribute" in the type declaration will be output.
  • -excludeUmlBeginEndTags: (Optional) When this switch is enabled, it will exclude the "@startuml" and "@enduml" tags from the puml file.

examples

puml-gen C:\Source\App1\ClassA.cs -public
puml-gen C:\Source\App1 C:\PlantUml\App1 -dir -ignore Private,Protected -createAssociation -allInOne
puml-gen C:\Source\App1 C:\PlantUml\App1 -dir -excludePaths bin,obj,Properties

Specification for conversion to PlantUML

Type Declaration

Type Keywords

|C# | PlantUML | |:----------------|-------------------:| | class | class | | struct | struct | | interface | interface | | enum | enum | | record | <<record>> class |

Type Modifiers

|C# | PlantUML | |:----------------|-------------------:| | abstract | abstract | | static | <<static>> | | partial | <<partial>> | | sealed | <<sealed>> |

  • C#
class ClassA {  
}
struct StructA {
}
interface InterfaceA {
}
record RecordA {
}
abstract class AbstractClass {
}
static class StaticClass {
}
sealed partial class ClassB{
}
enum EnumType{
  Apple,
  Orange,
  Grape
}
  • PlantUML
@startuml
class ClassA {
}
struct StructA {
}
interface InterfaceA {
}
class RecordA <<record>> {
}
abstract class AbstractClass {
}
class StaticClass <<static>> {
}
class ClassB <<sealed>> <<partial>> {
}
enum EnumType {
    Apple,
    Orange,
    Grape,
}
@enduml

TypeDeclaration.png

Generics Type

  • C#
class GenericsType<T1>{
}
class GenericsType<T1,T2>{
}
  • PlantUML
class "GenericsType`1"<T1>{
}
class "GenericsType`2"<T1,T2>{
}

GenericsTypeDeclaration.png

Member Declaration

Accessibility Modifiers

|C# | PlantUML | |:---------------------|-------------------:| | public | + | | internal | <<internal>> | | protected internal | # <<internal>> | | protected | # | | private | - |

Modifiers

|C# | PlantUML | |:-------------|-----------------:| | abstract | {abstract} | | static | {static} | | virtual | <<virtual>> | | override | <<override>> | | new | <<new>> | | readonly | <<readonly>> | | event | <<event>> |

Property Accessors

|C# | PlantUML | |:-------------------------------|------------------------------------:| | int Prop {get; set;} | Prop : int <<get>> <<set>> | | int Prop {get;} | Prop : int <get> | | int Prop {get; private set } | Prop : int <<get>><<private set>> | | int Prop => 100; | Prop : int <<get>> |

  • C#
abstract class AbstractClass
{
    protected int _x;
    internal int _y;
    protected internal int _z;
    public abstract void AbstractMethod();
    protected virtual void VirtualMethod(string s){

    }
    public string BaseMethod(int n){
        return "";
    }
}
class ClassM : AbstractClass
{
    public static readonly double PI =3.141592;
    public int PropA { get; set; }
    public int PropB { get; protected set; }
    public event EventHandler SomeEvent;
    public override void AbstractMethod(){
        
    }
    protected override void VirtualMethod(string s)
    {

    }
    public override string ToString()
    {
        return "override";
    }
    public new string BaseMethod(int n){
        return "new";
    }
}
  • PlantUML
abstract class AbstractClass {
    # _x : int
    <<internal>> _y : int
    # <<internal>> _z : int
    + {abstract} AbstractMethod() : void
    # <<virtual>> VirtualMethod(s:string) : void
    + BaseMethod(n:int) : string
}
class ClassM {
    + {static} <<readonly>> PI : double = 3.141592
    + PropA : int <<get>> <<set>>
    + PropB : int <<get>> <<protected set>>
    +  <<event>> SomeEvent : EventHandler 
    + <<override>> AbstractMethod() : void
    # <<override>> VirtualMethod(s:string) : void
    + <<override>> ToString() : string
    + <<new>> BaseMethod(n:int) : string
}
AbstractClass <|-- ClassM

MemberDeclaration.png

Field and Property Initializers

Only literal initializers are output.

  • C#
class ClassC
{
    private int fieldA = 123;
    public double Pi {get;} = 3.14159;
    protected List<string> Items = new List<string>(); 
}
  • PlantUML
class ClassC {
  - fieldA : int = 123
  + Pi : double = 3.14159
  # Items : List<string>
}

Initializer.png

Nested Class Declaration

Nested classes are expanded and associated with "OuterClass + - InnerClass".

  • C#
class OuterClass 
{
  class InnerClass 
  {
    struct InnerStruct 
    {

    }
  }
}
  • PlantUML
class OuterClass{

}
class InnerClass{

}
<<struct>> class InnerStruct {

}
OuterClass +- InnerClass
InnerClass +- InnerStruct

NestedClass.png

Inheritance Relationsips

  • C#
abstract class BaseClass
{
    public abstract void AbstractMethod();
    protected virtual int VirtualMethod(string s) => 0;
}
class SubClass : BaseClass
{
    public override void AbstractMethod() { }
    protected override int VirtualMethod(string s) => 1;
}

interface IInterfaceA {}
interface IInterfaceA<T>:IInterfaceA
{
    T Value { get; }
}
class ImplementClass : IInterfaceA<int>
{
    public int Value { get; }
}
  • PlantUML
abstract class BaseClass {
    + {abstract} AbstractMethod() : void
    # <<virtual>> VirtualMethod(s:string) : int
}
class SubClass {
    + <<override>> AbstractMethod() : void
    # <<override>> VirtualMethod(s:string) : int
}
interface IInterfaceA {
}
interface "IInterfaceA`1"<T> {
    Value : T <<get>>
}
class ImplementClass {
    + Value : int <<get>>
}
BaseClass <|-- SubClass
IInterfaceA <|-- "IInterfaceA`1"
"IInterfaceA`1" "<int>" <|-- ImplementClass

InheritanceRelationsips.png

Associations (from references of fields and properties)

If you specify the "createAssociation" option, object associations is

View on GitHub
GitHub Stars769
CategoryDevelopment
Updated9d ago
Forks142

Languages

C#

Security Score

100/100

Audited on Mar 25, 2026

No findings