FunctionalDdd.CommonValueObjects 3.0.0-alpha.3

This is a prerelease version of FunctionalDdd.CommonValueObjects.
dotnet add package FunctionalDdd.CommonValueObjects --version 3.0.0-alpha.3
                    
NuGet\Install-Package FunctionalDdd.CommonValueObjects -Version 3.0.0-alpha.3
                    
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.CommonValueObjects" Version="3.0.0-alpha.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="FunctionalDdd.CommonValueObjects" Version="3.0.0-alpha.3" />
                    
Directory.Packages.props
<PackageReference Include="FunctionalDdd.CommonValueObjects" />
                    
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.CommonValueObjects --version 3.0.0-alpha.3
                    
#r "nuget: FunctionalDdd.CommonValueObjects, 3.0.0-alpha.3"
                    
#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.CommonValueObjects@3.0.0-alpha.3
                    
#: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.CommonValueObjects&version=3.0.0-alpha.3&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=FunctionalDdd.CommonValueObjects&version=3.0.0-alpha.3&prerelease
                    
Install as a Cake Tool

Common Value Objects

NuGet Package

This library provides common value objects with source code generation for eliminating boilerplate code in domain-driven design applications.

Table of Contents

Installation

Install both packages via NuGet:

dotnet add package FunctionalDDD.CommonValueObjects
dotnet add package FunctionalDDD.CommonValueObjectGenerator

Important: Both packages are required:

  • FunctionalDDD.CommonValueObjects - Provides base classes and the EmailAddress value object
  • FunctionalDDD.CommonValueObjectGenerator - Source generator that creates implementations for RequiredString and RequiredGuid derived classes

Quick Start

RequiredString

Create strongly-typed string value objects using source code generation:

public partial class TrackingId : RequiredString
{
}

// Generated methods include:
var result = TrackingId.TryCreate("TRK-12345");
if (result.IsSuccess)
{
    var trackingId = result.Value;
    Console.WriteLine(trackingId); // Outputs: TRK-12345
}

// Supports IParsable<T>
var parsed = TrackingId.Parse("TRK-12345", null);

// Explicit cast operator
var trackingId = (TrackingId)"TRK-12345";

RequiredGuid

Create strongly-typed GUID value objects:

public partial class EmployeeId : RequiredGuid
{
}

// Generated methods include:
var employeeId = EmployeeId.NewUnique(); // Create new GUID
var result = EmployeeId.TryCreate(guid);
var result2 = EmployeeId.TryCreate("550e8400-e29b-41d4-a716-446655440000");

// Supports IParsable<T>
var parsed = EmployeeId.Parse("550e8400-e29b-41d4-a716-446655440000", null);

// Explicit cast operator
var employeeId = (EmployeeId)Guid.NewGuid();

EmailAddress

Pre-built email validation value object:

var result = EmailAddress.TryCreate("user@example.com");
if (result.IsSuccess)
{
    var email = result.Value;
    Console.WriteLine(email); // Outputs: user@example.com
}

// Validation errors
var invalid = EmailAddress.TryCreate("not-an-email");
// Returns: Error.Validation("Email address is not valid.", "email")

Core Concepts

Value Object Base Class Purpose Key Features
RequiredString String wrapper Non-empty strings Source generation, IParsable, explicit cast
RequiredGuid Guid wrapper Non-default GUIDs Source generation, NewUnique(), IParsable
EmailAddress String wrapper Email validation RFC 5322 compliant, case-insensitive

Generated Code Features:

  • TryCreate methods returning Result<T>
  • IParsable<T> implementation (Parse/TryParse)
  • Explicit cast operators
  • Validation with descriptive error messages
  • Property name inference for error messages

Best Practices

  1. Use partial classes
    Required for source code generation to work correctly.

  2. Leverage generated methods
    Use TryCreate for safe parsing that returns Result<T>.

  3. Compose with other value objects
    Combine multiple value objects using Combine for validation.

  4. Use meaningful names
    Class name becomes part of the error message (e.g., "Employee Id cannot be empty").

  5. Prefer specific types over primitives
    EmployeeId is more expressive than Guid or string.

Resources

Product Compatible and additional computed target framework versions.
.NET 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.

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.3 0 12/20/2025
2.1.10 659 12/3/2025
2.1.9 262 11/21/2025
2.1.1 211 4/26/2025
2.1.0-preview.3 91 4/26/2025
2.0.1 198 1/23/2025
2.0.0-alpha.62 74 1/8/2025
2.0.0-alpha.61 79 1/7/2025
2.0.0-alpha.60 98 12/7/2024
2.0.0-alpha.55 80 11/22/2024
2.0.0-alpha.52 89 11/7/2024
2.0.0-alpha.48 88 11/2/2024
2.0.0-alpha.47 87 10/30/2024
2.0.0-alpha.44 146 10/18/2024
2.0.0-alpha.42 105 10/14/2024
2.0.0-alpha.39 110 6/27/2024
2.0.0-alpha.38 104 4/24/2024
2.0.0-alpha.33 90 4/17/2024
2.0.0-alpha.26 94 4/9/2024
2.0.0-alpha.21 90 4/1/2024
2.0.0-alpha.19 103 3/5/2024
2.0.0-alpha.18 110 2/28/2024
2.0.0-alpha.17 102 2/26/2024
2.0.0-alpha.15 113 1/30/2024
2.0.0-alpha.8 94 1/27/2024
2.0.0-alpha.6 119 1/5/2024
1.1.1 642 11/15/2023
1.1.0-alpha.32 142 11/2/2023
1.1.0-alpha.30 240 10/31/2023
1.1.0-alpha.28 124 10/28/2023
1.1.0-alpha.27 125 10/28/2023
1.1.0-alpha.24 113 10/20/2023
1.1.0-alpha.23 125 10/13/2023
1.1.0-alpha.21 119 10/1/2023
1.1.0-alpha.20 117 9/30/2023
1.1.0-alpha.19 113 9/30/2023
1.1.0-alpha.18 123 9/29/2023
1.1.0-alpha.17 118 9/22/2023
1.1.0-alpha.13 121 9/16/2023
1.1.0-alpha.4 237 6/9/2023
1.1.0-alpha.3 165 6/8/2023
1.0.1 652 5/12/2023
0.1.0-alpha.40 218 4/6/2023
0.1.0-alpha.39 220 4/3/2023
0.1.0-alpha.38 242 4/2/2023
0.1.0-alpha.37 223 3/31/2023
0.1.0-alpha.35 215 3/29/2023
0.1.0-alpha.34 192 3/28/2023
0.1.0-alpha.32 239 3/18/2023
0.1.0-alpha.30 229 3/11/2023
0.1.0-alpha.27 226 3/7/2023
0.1.0-alpha.24 230 2/15/2023
0.1.0-alpha.22 211 2/15/2023
0.1.0-alpha.20 228 2/13/2023
0.1.0-alpha.19 175 2/13/2023
0.0.1-alpha.14 243 1/4/2023
0.0.1-alpha.4 215 12/30/2022
0.0.1-alpha.3 232 12/23/2022
0.0.1-alpha 617 12/21/2022