Proxoft.ValueObjects
1.1.0
dotnet add package Proxoft.ValueObjects --version 1.1.0
NuGet\Install-Package Proxoft.ValueObjects -Version 1.1.0
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="Proxoft.ValueObjects" Version="1.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Proxoft.ValueObjects --version 1.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Proxoft.ValueObjects, 1.1.0"
#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 Proxoft.ValueObjects as a Cake Addin #addin nuget:?package=Proxoft.ValueObjects&version=1.1.0 // Install Proxoft.ValueObjects as a Cake Tool #tool nuget:?package=Proxoft.ValueObjects&version=1.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Value objects
What is and why should you use a value object: https://learn.microsoft.com/en-us/dotnet/architecture/microservices/microservice-ddd-cqrs-patterns/implement-value-objects
The library contains some base implementations of Int, String, NullableString, Decimal and Double value objects.
Usage
public class FooId: IntValueObject<FooId>
{
public static readonly FooId None = new(0);
public class FooId(int value) : base(value, minValue: 0)
{
}
public FooId Next()
{
return new FooId(this + 1);
}
}
public class Lat : DecimalValueObject<Lat>
{
public static readonly Lat Undefined = new(-100); // whatever value outside of the range
public Lat(decimal value) : base(
value,
Guard)
{
}
private static void Guard(decimal value)
{
if(value == -100)
{
return;
}
GuardFunctions.ThrowIfNotInRange(value, -90m, 90m);
}
}
For System.Text.Json use JsonConverters:
public class Foo(int value) : IntValueObject<Foo>(value, minValue: 5)
{
}
JsonSerializerOptions _options = new()
{
Converters = {
new IntValueObjectConverter<Foo>()
}
};
// later in code
Foo f = new(15);
string json = JsonSerializer.Serialize(f, _options);
// json is "15"
Foo? deserialized = JsonSerializer.Deserialize<Foo>("25", _options);
// deserialized == new Foo(25)
of a generic approach
public class Foo(int value) : IntValueObject<Foo>(value, minValue: 5)
{
}
JsonSerializerOptions _options = new()
{
Converters = {
new DefaultValueObjectJsonConverter()
}
};
// later in code
Foo f = new(15);
string json = JsonSerializer.Serialize(f, _options);
// json is "15"
Foo? deserialized = JsonSerializer.Deserialize<Foo>("25", _options);
// deserialized == new Foo(25)
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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.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.