FunctionalDdd.CommonValueObjects
2.0.0-alpha.18
See the version list below for details.
dotnet add package FunctionalDdd.CommonValueObjects --version 2.0.0-alpha.18
NuGet\Install-Package FunctionalDdd.CommonValueObjects -Version 2.0.0-alpha.18
<PackageReference Include="FunctionalDdd.CommonValueObjects" Version="2.0.0-alpha.18" />
paket add FunctionalDdd.CommonValueObjects --version 2.0.0-alpha.18
#r "nuget: FunctionalDdd.CommonValueObjects, 2.0.0-alpha.18"
// Install FunctionalDdd.CommonValueObjects as a Cake Addin #addin nuget:?package=FunctionalDdd.CommonValueObjects&version=2.0.0-alpha.18&prerelease // Install FunctionalDdd.CommonValueObjects as a Cake Tool #tool nuget:?package=FunctionalDdd.CommonValueObjects&version=2.0.0-alpha.18&prerelease
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, IParsable<TrackingId>
{
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 TrackingId Parse(string s, IFormatProvider? provider)
{
var r = TryCreate(s);
if (r.IsFailure)
throw new FormatException(r.Error.Message);
return r.Value;
}
public static bool TryParse([NotNullWhen(true)] string? s, IFormatProvider? provider, [MaybeNullWhen(false)] out TrackingId result)
{
var r = TryCreate(s);
if (r.IsFailure)
{
result = default;
return false;
}
result = r.Value;
return true;
}
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, IParsable<EmployeeId>
{
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 Parse(string s, IFormatProvider? provider)
{
var r = TryCreate(s);
if (r.IsFailure)
throw new FormatException(r.Error.Message);
return r.Value;
}
public static bool TryParse([NotNullWhen(true)] string? s, IFormatProvider? provider, [MaybeNullWhen(false)] out EmployeeId result)
{
var r = TryCreate(s);
if (r.IsFailure)
{
result = default;
return false;
}
result = r.Value;
return true;
}
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("Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)", "employeeId"))
.Ensure(_ => parsedGuid != Guid.Empty, CannotBeEmptyError)
.Map(guid => new EmployeeId(parsedGuid));
}
}
Product | Versions 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. |
-
net8.0
- FunctionalDdd.DomainDrivenDesign (>= 2.0.0-alpha.18)
- FunctionalDdd.RailwayOrientedProgramming (>= 2.0.0-alpha.18)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on FunctionalDdd.CommonValueObjects:
Package | Downloads |
---|---|
FunctionalDdd.SampleUserLibrary
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
2.0.0-alpha.52 | 48 | 11/7/2024 |
2.0.0-alpha.48 | 42 | 11/2/2024 |
2.0.0-alpha.47 | 43 | 10/30/2024 |
2.0.0-alpha.44 | 100 | 10/18/2024 |
2.0.0-alpha.42 | 53 | 10/14/2024 |
2.0.0-alpha.39 | 65 | 6/27/2024 |
2.0.0-alpha.38 | 65 | 4/24/2024 |
2.0.0-alpha.33 | 65 | 4/17/2024 |
2.0.0-alpha.26 | 69 | 4/9/2024 |
2.0.0-alpha.21 | 67 | 4/1/2024 |
2.0.0-alpha.19 | 68 | 3/5/2024 |
2.0.0-alpha.18 | 78 | 2/28/2024 |
2.0.0-alpha.17 | 71 | 2/26/2024 |
2.0.0-alpha.15 | 82 | 1/30/2024 |
2.0.0-alpha.8 | 66 | 1/27/2024 |
2.0.0-alpha.6 | 96 | 1/5/2024 |
1.1.1 | 569 | 11/15/2023 |
1.1.0-alpha.32 | 104 | 11/2/2023 |
1.1.0-alpha.30 | 212 | 10/31/2023 |
1.1.0-alpha.28 | 95 | 10/28/2023 |
1.1.0-alpha.27 | 94 | 10/28/2023 |
1.1.0-alpha.24 | 83 | 10/20/2023 |
1.1.0-alpha.23 | 90 | 10/13/2023 |
1.1.0-alpha.21 | 84 | 10/1/2023 |
1.1.0-alpha.20 | 82 | 9/30/2023 |
1.1.0-alpha.19 | 80 | 9/30/2023 |
1.1.0-alpha.18 | 90 | 9/29/2023 |
1.1.0-alpha.17 | 83 | 9/22/2023 |
1.1.0-alpha.13 | 82 | 9/16/2023 |
1.1.0-alpha.4 | 150 | 6/9/2023 |
1.1.0-alpha.3 | 92 | 6/8/2023 |
1.0.1 | 528 | 5/12/2023 |
0.1.0-alpha.40 | 123 | 4/6/2023 |
0.1.0-alpha.39 | 123 | 4/3/2023 |
0.1.0-alpha.38 | 152 | 4/2/2023 |
0.1.0-alpha.37 | 129 | 3/31/2023 |
0.1.0-alpha.35 | 123 | 3/29/2023 |
0.1.0-alpha.34 | 108 | 3/28/2023 |
0.1.0-alpha.32 | 144 | 3/18/2023 |
0.1.0-alpha.30 | 135 | 3/11/2023 |
0.1.0-alpha.27 | 129 | 3/7/2023 |
0.1.0-alpha.24 | 132 | 2/15/2023 |
0.1.0-alpha.22 | 117 | 2/15/2023 |
0.1.0-alpha.20 | 132 | 2/13/2023 |
0.1.0-alpha.19 | 93 | 2/13/2023 |
0.0.1-alpha.14 | 154 | 1/4/2023 |
0.0.1-alpha.4 | 134 | 12/30/2022 |
0.0.1-alpha.3 | 142 | 12/23/2022 |
0.0.1-alpha | 507 | 12/21/2022 |