ctorgen 0.1.0

dotnet tool install --global ctorgen --version 0.1.0
                    
This package contains a .NET tool you can call from the shell/command line.
dotnet new tool-manifest
                    
if you are setting up this repo
dotnet tool install --local ctorgen --version 0.1.0
                    
This package contains a .NET tool you can call from the shell/command line.
#tool dotnet:?package=ctorgen&version=0.1.0
                    
nuke :add-package ctorgen --version 0.1.0
                    

ctorgen

CLI tool for generating ladder-style constructors for C# classes

ctorgen eliminates repetitive constructor boilerplate by generating a full chain of overloaded constructors where parameters are progressively replaced with their hash representations.


📚 Table of Contents


✨ Features

  • Generates all constructor overloads automatically
  • Implements ladder-style chaining via this(...)
  • Seamlessly transitions from values → hashes
  • Supports both CLI and JSON configuration
  • Deterministic and consistent output
  • Zero boilerplate for hash-driven models

📦 Installation

Global tool

dotnet tool install --global ctorgen

Local build (run from src folder)

dotnet pack -c Release
dotnet tool install --global --add-source bin/Release ctorgen

🚀 Quick Start

1. Create config

ctorgen init

Creates:

ctorgen.json

2. Generate constructors

ctorgen --config=ctorgen.json

Output:

MyModelHash.Ctors.cs

🖥 CLI Usage

ctorgen --name=MyModelHash --param="id:IGuid:new DeterminedHash(id)" --param="name:IString:new DeterminedHash(name)" --out=MyModelHash.Ctors.cs

⚠️ Parameter Format

name:type:hashExpr

Example:

--param="id:IGuid:new DeterminedHash(id)"

❗ Important: quoting

If your expression contains spaces, wrap it in quotes:

✅ Correct:

--param="id:IGuid:new DeterminedHash(id)"

❌ Incorrect:

--param=id:IGuid:new DeterminedHash(id)

⚙️ Configuration

Example ctorgen.json:

{
  "ClassName": "MyModelHash",
  "Params": [
    {
      "Name": "id",
      "Type": "IGuid",
      "Hash": "new DeterminedHash(id)"
    },
    {
      "Name": "name",
      "Type": "IString",
      "Hash": "new DeterminedHash(name)"
    }
  ]
}

🧬 Generated Output

Delegating constructor

public MyModelHash(
    IGuid id,
    IString name
)
    : this(
        new DeterminedHash(id),
        name
    )
{ }

Final constructor

public MyModelHash(
    IDeterminedHash idHash,
    IDeterminedHash nameHash
)
{
    _idHash = idHash;
    _nameHash = nameHash;
}

🧠 How It Works

For a model with N parameters, ctorgen:

  1. Generates all combinations using a bitmask
  2. Sorts them by number of hashed parameters
  3. Builds a constructor chain
  4. Each step converts one value → hash
  5. Final constructor assigns fields

Result:

values → partial hashes → full hashes

📊 Before / After

❌ Manual

  • Dozens of constructor overloads
  • Easy to make mistakes
  • Hard to maintain

✅ ctorgen

ctorgen --config=ctorgen.json
  • All combinations generated automatically
  • Clean and consistent
  • Minimal maintenance

📋 Arguments

Argument Description
--name Target class name
--param Parameter (name:type:hashExpr)
--config JSON config path
--out Output file (default {ClassName}.Ctors.cs)
init Generate config template
--help Show help

📁 Examples

examples/
├── ctorgen.json
└── MyModelHash.Ctors.cs

📄 License

MIT


🤝 Contributing

Contributions, issues, and feature requests are welcome.

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.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

Version Downloads Last Updated
0.1.0 101 4/26/2026