MermaidClassDiagramGenerator 1.2.1

dotnet add package MermaidClassDiagramGenerator --version 1.2.1                
NuGet\Install-Package MermaidClassDiagramGenerator -Version 1.2.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MermaidClassDiagramGenerator" Version="1.2.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MermaidClassDiagramGenerator --version 1.2.1                
#r "nuget: MermaidClassDiagramGenerator, 1.2.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install MermaidClassDiagramGenerator as a Cake Addin
#addin nuget:?package=MermaidClassDiagramGenerator&version=1.2.1

// Install MermaidClassDiagramGenerator as a Cake Tool
#tool nuget:?package=MermaidClassDiagramGenerator&version=1.2.1                

Mermaid Class Diagram Generator

Effortlessly generate stunning Mermaid.js class diagrams from your C# domain models and export them to Markdown.

🛠️ Features

  • Automatic Diagram Generation: Create class diagrams directly from your C# domain models.
  • Recursive Documentation: Automatically includes related and nested types for comprehensive diagrams.
  • Markdown Export: Outputs diagrams as .md files, perfect for README files and other Markdown-supported documentation platforms.
  • Easy Configuration: Simple setup with configurable parameters to specify assemblies and domain types.

📦 Installation

You can install the MermaidClassDiagramGenerator NuGet package via the .NET CLI or through Visual Studio's NuGet Package Manager.

Using .NET CLI

dotnet add package MermaidClassDiagramGenerator

Using Package Manager Console

Install-Package MermaidClassDiagramGenerator

Using .NET CLI with Specific Version

dotnet add package MermaidClassDiagramGenerator --version x.y.z

Replace x.y.z with the desired version number.

🚀 Usage

The easiest way to use MermaidClassDiagramGenerator is by adding it to a console application within your solution.

Steps:

  1. Create a Console App:
    • In your solution, add a new Console App project where you will use the generator.
  2. Install the Package:
    • Install MermaidClassDiagramGenerator via NuGet as shown above.
  3. Implement the Generator:
    • Use the following example to set up and generate your class diagram.

Basic Example:

using System;
using System.Collections.Generic;
using System.Reflection;
using MermaidClassDiagramGenerator;

namespace YourNamespace
{
    class Program
    {
        static void Main(string[] args)
        {
            var generator = new DiagramGenerator(
                outputFilePath: "diagram.md",
                assembliesToScan: new List<Assembly> { Assembly.GetExecutingAssembly() },
                domainTypes: new List<Type> { typeof(Car), typeof(Wheels) },
                generateWithoutProperties: false
            );
            
            generator.Generate();

            Console.WriteLine("Mermaid.js class diagram generated successfully at diagram.md");
        }
    }

    // Example domain classes
    public class Car
    {
        public int Id { get; set; }
        public string Model { get; set; }
        public Wheels Wheels { get; set; }
    }

    public class Wheels
    {
        public int Count { get; set; }
        public string Type { get; set; }
    }
}

Parameters:

  • outputFilePath (string): The file path where the generated Mermaid.js diagram will be saved. Important: The file must have a .md extension as the generator outputs the diagram in Markdown format, which supports Mermaid.js syntax.
  • assembliesToScan (IEnumerable<Assembly>): A collection of assemblies that the generator will scan to discover domain classes. These assemblies should contain the classes you want to include in the diagram.
  • domainTypes (IEnumerable<Type>): A list of domain class types that the generator should document. The generator processes these types recursively, meaning that if a domain class (e.g., Auto) has properties of other domain types (e.g., Wheels), those related types will also be included in the generated class diagram automatically.
  • generateWithoutProperties (bool): A boolean flag indicating whether to generate the class diagram without including property details. If set to true, the diagram will display class names without listing their properties.

📄 Example Output

After running the generator, your diagram.md might contain:

classDiagram
class Car{
  +Int32 Id
  +String Model
}

class Wheels{
  +Int32 Count
  +String Type
}

Car o-- Wheels

Advanced Examples

📜 License

This project is licensed under the MIT License.

🙏 Contributing

Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.

📫 Contact

For any questions or support, please open an issue on the GitHub repository.


Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.2.1 51 11/19/2024
1.2.0 35 11/18/2024
1.1.0 91 11/11/2024
1.0.0 81 11/8/2024

### 1.0.0
     - Initial version.
     - Recursive class diagram generation.
     - Inheritance supported.
     
     ### 1.1.0
     - ExcludeFromDiagram Attribute
     - Generic classes are formatted correctly in mermaid.js
     - Inheritance supports generic classes
     - Public Type extensions
     - Extra examples
     
     ### 1.2.0
     - Documents base type correctly
     - Recursion working for generic base types
     - added unit tests
     
     ### 1.2.1
     - Only add user defined types to diagram + directly passed types