RSCG – PlantUmlClassDiagramGenerator
| name | PlantUmlClassDiagramGenerator |
| nuget |
https://www.nuget.org/packages/PlantUmlClassDiagramGenerator.SourceGenerator/ https://www.nuget.org/packages/PlantUmlClassDiagramGenerator.Attributes/ |
| link | https://github.com/pierre3/PlantUmlClassDiagramGenerator/ |
| author | Hirotada Kobayashi |
Generating UML from class definitions
This is how you can use PlantUmlClassDiagramGenerator .
The code that you start with is
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<!--<PackageReference Include="PlantUmlClassDiagramGenerator.Attributes" Version="1.3.0.1" />-->
<PackageReference Include="PlantUmlClassDiagramGenerator.SourceGenerator" Version="0.1.9-alpha">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<PropertyGroup>
<!--<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">-->
<DefineConstants>$(DefineConstants);GENERATE_PLANTUML</DefineConstants>
</PropertyGroup>
<PropertyGroup>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath>
</PropertyGroup>
</Project>
The code that you will use is
// See https://aka.ms/new-console-template for more information
using DemoClass2Text;
Person person = new()
{
FirstName = "Andrei",
LastName = "Ignat"
};
Console.WriteLine(person.FullName());
namespace DemoClass2Text
{
[PlantUmlClassDiagramGenerator.SourceGenerator.Attributes.PlantUmlDiagram]
internal class Person
{
public string? FirstName { get; set; }
public string? LastName { get; set; }
public string? FullName() => $"{FirstName} {LastName}";
}
}
The code that is generated is
namespace PlantUmlClassDiagramGenerator.SourceGenerator.Attributes;
[System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Interface | System.AttributeTargets.Enum | System.AttributeTargets.Struct)]
internal class PlantUmlDiagramAttribute : System.Attribute
{ }
@startuml Person
class Person {
+ FirstName : string? <<get>> <<set>>
+ LastName : string? <<get>> <<set>>
+ FullName() : string?
+ Person()
}
@enduml
Code and pdf at
https://ignatandrei.github.io/RSCG_Examples/v2/docs/PlantUmlClassDiagramGenerator
Leave a Reply