FunctionalDdd.CommonValueObjects 1.1.1

There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package FunctionalDdd.CommonValueObjects --version 1.1.1
NuGet\Install-Package FunctionalDdd.CommonValueObjects -Version 1.1.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="FunctionalDdd.CommonValueObjects" Version="1.1.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add FunctionalDdd.CommonValueObjects --version 1.1.1
#r "nuget: FunctionalDdd.CommonValueObjects, 1.1.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 FunctionalDdd.CommonValueObjects as a Cake Addin
#addin nuget:?package=FunctionalDdd.CommonValueObjects&version=1.1.1

// Install FunctionalDdd.CommonValueObjects as a Cake Tool
#tool nuget:?package=FunctionalDdd.CommonValueObjects&version=1.1.1

Common Value Object

This library contains common value objects used across the applications. At this point there are three classes:

  • EmailAddress - Email address value object that validates the email address format.
  • RequiredString - String value object that cannot be null or empty.
  • RequiredGuid - Guid value object that cannot be null or default.

Usage

RequiredString and RequiredGuid uses source code generation to generate the TryCreate method and other boilerplate code. Make sure it is declared as partial class so that the source code generator can do the rest.

Here is an example of how to use RequiredString:

public partial class TrackingId : RequiredString
{
}

The source code generator will generate the following

public partial class TrackingId : RequiredString
{
    protected static readonly Error CannotBeEmptyError = Error.Validation("Tracking Id cannot be empty.", "trackingId");

    private TrackingId(string value) : base(value)
    {
    }

    public static explicit operator TrackingId(string trackingId) => TryCreate(trackingId).Value;

    public static Result<TrackingId> TryCreate(string? requiredStringOrNothing) =>
        requiredStringOrNothing
            .EnsureNotNullOrWhiteSpace(CannotBeEmptyError)
            .Map(str => new TrackingId(str));
}

Here is an example of how to use RequiredGuid:

public partial class EmployeeId : RequiredGuid
{
}

The source code generator will generate the following

public partial class EmployeeId : RequiredGuid
{
    protected static readonly Error CannotBeEmptyError = Error.Validation("Employee Id cannot be empty.", "employeeId");

    private EmployeeId(Guid value) : base(value)
    {
    }

    public static explicit operator EmployeeId(Guid employeeId) => TryCreate(employeeId).Value;

    public static EmployeeId NewUnique() => new(Guid.NewGuid());

    public static Result<EmployeeId> TryCreate(Guid? requiredGuidOrNothing) =>
        requiredGuidOrNothing
            .ToResult(CannotBeEmptyError)
            .Ensure(x => x != Guid.Empty, CannotBeEmptyError)
            .Map(guid => new EmployeeId(guid));

    public static Result<EmployeeId> TryCreate(string? stringOrNull)
    {
         Guid parsedGuid = Guid.Empty;
         return stringOrNull
            .ToResult(CannotBeEmptyError)
            .Ensure(x => Guid.TryParse(x, out parsedGuid), Error.Validation("string is not in valid format.", "employeeId"))
            .Ensure(_ => parsedGuid != Guid.Empty, CannotBeEmptyError)
            .Map(guid => new EmployeeId(parsedGuid));
    }
}
Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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.

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
2.0.0-alpha.38 34 4/24/2024
2.0.0-alpha.33 47 4/17/2024
2.0.0-alpha.26 52 4/9/2024
2.0.0-alpha.21 52 4/1/2024
2.0.0-alpha.19 56 3/5/2024
2.0.0-alpha.18 60 2/28/2024
2.0.0-alpha.17 59 2/26/2024
2.0.0-alpha.15 70 1/30/2024
2.0.0-alpha.8 47 1/27/2024
2.0.0-alpha.6 77 1/5/2024
1.1.1 529 11/15/2023
1.1.0-alpha.32 84 11/2/2023
1.1.0-alpha.30 188 10/31/2023
1.1.0-alpha.28 74 10/28/2023
1.1.0-alpha.27 74 10/28/2023
1.1.0-alpha.24 61 10/20/2023
1.1.0-alpha.23 69 10/13/2023
1.1.0-alpha.21 69 10/1/2023
1.1.0-alpha.20 66 9/30/2023
1.1.0-alpha.19 66 9/30/2023
1.1.0-alpha.18 69 9/29/2023
1.1.0-alpha.17 63 9/22/2023
1.1.0-alpha.13 66 9/16/2023
1.1.0-alpha.4 123 6/9/2023
1.1.0-alpha.3 72 6/8/2023
1.0.1 491 5/12/2023
0.1.0-alpha.40 104 4/6/2023
0.1.0-alpha.39 105 4/3/2023
0.1.0-alpha.38 128 4/2/2023
0.1.0-alpha.37 109 3/31/2023
0.1.0-alpha.35 103 3/29/2023
0.1.0-alpha.34 93 3/28/2023
0.1.0-alpha.32 120 3/18/2023
0.1.0-alpha.30 117 3/11/2023
0.1.0-alpha.27 114 3/7/2023
0.1.0-alpha.24 106 2/15/2023
0.1.0-alpha.22 99 2/15/2023
0.1.0-alpha.20 108 2/13/2023
0.1.0-alpha.19 78 2/13/2023
0.0.1-alpha.14 132 1/4/2023
0.0.1-alpha.4 120 12/30/2022
0.0.1-alpha.3 128 12/23/2022
0.0.1-alpha 475 12/21/2022