FunctionalDdd.PrimitiveValueObjectGenerator 3.0.0-alpha.44

This is a prerelease version of FunctionalDdd.PrimitiveValueObjectGenerator.
dotnet add package FunctionalDdd.PrimitiveValueObjectGenerator --version 3.0.0-alpha.44
                    
NuGet\Install-Package FunctionalDdd.PrimitiveValueObjectGenerator -Version 3.0.0-alpha.44
                    
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="FunctionalDdd.PrimitiveValueObjectGenerator" Version="3.0.0-alpha.44" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="FunctionalDdd.PrimitiveValueObjectGenerator" Version="3.0.0-alpha.44" />
                    
Directory.Packages.props
<PackageReference Include="FunctionalDdd.PrimitiveValueObjectGenerator" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add FunctionalDdd.PrimitiveValueObjectGenerator --version 3.0.0-alpha.44
                    
#r "nuget: FunctionalDdd.PrimitiveValueObjectGenerator, 3.0.0-alpha.44"
                    
#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.
#:package FunctionalDdd.PrimitiveValueObjectGenerator@3.0.0-alpha.44
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=FunctionalDdd.PrimitiveValueObjectGenerator&version=3.0.0-alpha.44&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=FunctionalDdd.PrimitiveValueObjectGenerator&version=3.0.0-alpha.44&prerelease
                    
Install as a Cake Tool

CommonValueObjectGenerator

NuGet

Roslyn source generator for creating strongly-typed value objects with automatic validation and IParsable support.

What It Does

Automatically generates boilerplate code for classes inheriting from RequiredString or RequiredGuid:

// You write this:
public partial class OrderId : RequiredGuid
{
}

// Generator creates:
// - TryCreate(Guid?) method returning Result<OrderId>
// - TryCreate(string?) method returning Result<OrderId>
// - NewUnique() method for new GUIDs
// - Parse(string, IFormatProvider?) method (IParsable)
// - TryParse(string?, IFormatProvider?, out OrderId) method (IParsable)
// - Explicit cast operator from Guid
// - Validation error messages

Installation

This package is included automatically when you install FunctionalDDD.CommonValueObjects:

dotnet add package FunctionalDDD.CommonValueObjects

Note: Both packages are required - the main package provides base classes, this generator creates the implementations.

Generated API

For RequiredString Classes

public partial class ProductName : RequiredString
{
}

// Generated members:
ProductName.TryCreate(string?)                           // Result<ProductName>
ProductName.Parse(string, IFormatProvider?)              // ProductName (throws)
ProductName.TryParse(string?, IFormatProvider?, out...)  // bool
(ProductName)"ABC"                                       // Explicit cast

For RequiredGuid Classes

public partial class UserId : RequiredGuid
{
}

// Generated members:
UserId.NewUnique()                                       // New GUID
UserId.TryCreate(Guid?)                                  // Result<UserId>
UserId.TryCreate(string?)                                // Result<UserId>
UserId.Parse(string, IFormatProvider?)                   // UserId (throws)
UserId.TryParse(string?, IFormatProvider?, out...)       // bool
(UserId)Guid.NewGuid()                                   // Explicit cast

Requirements

  • .NET Standard 2.0 compatible (source generators must target netstandard2.0)
  • C# 9.0+ for partial class support
  • Requires FunctionalDDD.CommonValueObjects package

How It Works

  1. Analyzes your code for partial classes inheriting from RequiredString or RequiredGuid
  2. Generates implementation code at compile-time
  3. Code appears in IntelliSense automatically
  4. No runtime reflection - all compile-time

Validation

Generated code includes automatic validation:

var result = ProductName.TryCreate("");  
// Returns: Result.Failure("Product Name cannot be empty.")

var result = UserId.TryCreate(Guid.Empty);
// Returns: Result.Failure("User Id cannot be empty.")

Error messages use the class name (e.g., "Product Name" from "ProductName").

Source Code

This is a source generator - it runs at compile-time and generates C# code. The generated code is visible in:

  • Visual Studio: Project ? Dependencies ? Analyzers ? FunctionalDdd.CommonValueObjectGenerator
  • Output: obj/Debug/net10.0/generated/

Resources

License

MIT � Xavier John

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

  • .NETStandard 2.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
3.0.0-alpha.44 34 1/13/2026