This is a generator to create a class-diagram of PlantUML from the C# source code.
This is a generator to create a class-diagram of PlantUML from the C# source code.
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 |
The class diagram is automatically generated by the Roslyn Source Generator. Details are provided in the link below.
Nuget Gallery: https://www.nuget.org/packages/PlantUmlClassDiagramGenerator
Download and install the .NET 8.0 SDK or newer. Once installed, run the following command.
dotnet tool install --global PlantUmlClassDiagramGeneratorRun the "puml-gen" command.
puml-gen InputPath [OutputPath] [-dir] [-addPackageTags] [-public | -ignore IgnoreAccessibilities] [-excludePaths ExcludePathList] [-createAssociation]examples
puml-gen C:\Source\App1\ClassA.cs -publicpuml-gen C:\Source\App1 C:\PlantUml\App1 -dir -ignore Private,Protected -createAssociation -allInOnepuml-gen C:\Source\App1 C:\PlantUml\App1 -dir -excludePaths bin,obj,Properties| C# | PlantUML |
|---|---|
class |
class |
struct |
struct |
interface |
interface |
enum |
enum |
record |
> class |
| C# | PlantUML |
|---|---|
abstract |
abstract |
static |
> |
partial |
<> |
sealed |
> |
class ClassA {
}
struct StructA {
}
interface InterfaceA {
}
record RecordA {
}
abstract class AbstractClass {
}
static class StaticClass {
}
sealed partial class ClassB{
}
enum EnumType{
Apple,
Orange,
Grape
}@startuml
class ClassA {
}
struct StructA {
}
interface InterfaceA {
}
class RecordA > {
}
abstract class AbstractClass {
}
class StaticClass > {
}
class ClassB > <> {
}
enum EnumType {
Apple,
Orange,
Grape,
}
@endumlclass GenericsType{
}
class GenericsType{
}class "GenericsType`1"{
}
class "GenericsType`2"{
}| C# | PlantUML |
|---|---|
public |
+ |
internal |
<> |
protected internal |
# <> |
protected |
# |
private |
- |
| C# | PlantUML |
|---|---|
abstract |
{abstract} |
static |
{static} |
virtual |
> |
override |
> |
new |
> |
readonly |
> |
event |
> |
| C# | PlantUML |
|---|---|
int Prop {get; set;} |
Prop : int > > |
int Prop {get;} |
Prop : int |
int Prop {get; private set } |
Prop : int ><> |
int Prop => 100; |
Prop : int > |
…abstract class AbstractClass {
# _x : int
<> _y : int
# <> _z : int
+ {abstract} AbstractMethod() : void
# > VirtualMethod(s:string) : void
+ BaseMethod(n:int) : string
}
class ClassM {
+ {static} > PI : double = 3.141592
+ PropA : int > >
+ PropB : int > <>
+ > SomeEvent : EventHandler
+ > AbstractMethod() : void
# > VirtualMethod(s:string) : void
+ > ToString() : string
+ > BaseMethod(n:int) : string
}
AbstractClass Items = new List();
}class ClassC {
- fieldA : int = 123
+ Pi : double = 3.14159
# Items : List
}Nested classes are expanded and associated with "OuterClass + - InnerClass".
class OuterClass
{
class InnerClass
{
struct InnerStruct
{
}
}
}class OuterClass{
}
class InnerClass{
}
> class InnerStruct {
}
OuterClass +- InnerClass
InnerClass +- InnerStructabstract 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:IInterfaceA
{
T Value { get; }
}
class ImplementClass : IInterfaceA
{
public int Value { get; }
}abstract class BaseClass {
+ {abstract} AbstractMethod() : void
# > VirtualMethod(s:string) : int
}
class SubClass {
+ > AbstractMethod() : void
# > VirtualMethod(s:string) : int
}
interface IInterfaceA {
}
interface "IInterfaceA`1" {
Value : T >
}
class ImplementClass {
+ Value : int >
}
BaseClass Strings{get;} = new List();
public Type1 Prop1{get;set;}
public Type2 field1;
}
class Type1 {
public int value1{get;set;}
}
class Type2{
public string string1{get;set;}
public ExternalType Prop2 {get;set;}
}@startuml
class ClassA {
}
class Type1 {
+ value1 : int > >
}
class Type2 {
+ string1 : string > >
}
class "IList`1" {
}
ClassA o-> "Strings" "IList`1"
ClassA --> "Prop1" Type1
ClassA --> "field1" Type2
Type2 --> "Prop2" ExternalType
@endumlRecord types in C# 9 can have a parameter list. In these cases these parameters are added as properties to the class.
record Person(string Name, int Age);
record Group(string GroupName) {
public Person[] Members { get; init; }
}@startuml
class Person > {
+ Name : string > <>
+ Age : int > <>
}
class Group > {
+ GroupName : string > <>
+ Members : Person[] > <>
}
@endumlYou can add the package PlantUmlClassDiagramGenerator.Attributes to your C# project for attribute-based configuration.
Only types to which PlantUmlDiagramAttribute has been added will be output. This attribute is enabled if the -attributeRequired switch is added to the command line argument.
This attribute can be added only to type declalerations.
class ClassA
{
public string Name { get; set; }
public int Age { get; set; }
}
[PlantUmlDiagram]
class ClassB
{
public string Name { get; set; }
public int Age { get; set; }
}Only ClassB with PlantUmlDiagramAttribute will be output.
@startuml
class ClassB {
+ Name : string > >
+ Age : int > >
}
@endumlElements with this attribute added are excluded from the output.
[PlantUmlIgnore]
class ClassA
{
public string Name { get; set; }
public int Age { get; set; }
}
class ClassB
{
public string Name { get; set; }
[PlantUmlIgnore]
public int Age { get; set; }
}
class ClassC
{
public string Name { get; set; }
public int Age { get; set; }
[PlantUmlIgnore]
public ClassC(string name, int age) => (Name, Age) = (name, age);
public void MethodA();
[PlantUmlIgnore]
public void MethodB();
}@startuml
class ClassB {
+ Name : string
}
class ClassC {
+ Name : string
+ Age : int
+ MethodA() : void
}
@endumlBy adding this attribute, you can define association between classes. This attribute can be added to properties, fields and method parameters.
The details of the association are defined in the following properties.
…@startuml
class Parameters {
+ A : string > >
+ B : string > >
}
class CustomAssociationSample {
}
class CollectionItemsSample {
}
class MethodParamtersSample {
+ Run(p:Parameters) : void
+ MyClass(logger:ILogger)
}
CustomAssociationSample "RootLabel" *--> "LeafLabel" Name : "Label"
CollectionItemsSample o-- "0..*" Item : "Items"
MethodParamtersSample ..> Parameters : "use"
MethodParamtersSample ..> ILogger : "Injection"
@endumlThis attribute can be added to properties and fields. Propertie
No open issues yet, or sync has not completed.