DotNetThoughts.Results.Validation
1.5.11
dotnet add package DotNetThoughts.Results.Validation --version 1.5.11
NuGet\Install-Package DotNetThoughts.Results.Validation -Version 1.5.11
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="DotNetThoughts.Results.Validation" Version="1.5.11" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DotNetThoughts.Results.Validation --version 1.5.11
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: DotNetThoughts.Results.Validation, 1.5.11"
#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 DotNetThoughts.Results.Validation as a Cake Addin #addin nuget:?package=DotNetThoughts.Results.Validation&version=1.5.11 // Install DotNetThoughts.Results.Validation as a Cake Tool #tool nuget:?package=DotNetThoughts.Results.Validation&version=1.5.11
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Validating input
Fluent Validation made me do this. The problem with fluent validation is that all it does is validating your data, but your validated data will still have types that allow invalid values. When fluent validation validates your nullable decimal to be not null, you will still sit there with a nullable decimal type. What I want, after such validation, is a non-nullable decimal.
Usage examples
decimal? nullableDecimal = 10;
Result<decimal> validDecimal = GeneralValidation.Value(nullableDecimal);
if (validDecimal.IsValid)
{
Console.WriteLine(validDecimal.Value);
}
else
{
Console.WriteLine(validDecimal.ErrorMessage);
}
static Result<Id<T>> FromInput<T>(string? candidateId) =>
long.TryParse(candidateId, out var longCandidate)
? FromInput<T>(longCandidate)
: Result<Id<T>>.Error(new InvalidIdError(candidateId));
public Result<Unit> PlaceOrder(string? currency, int? amount, string? paymentMethod, string? orderId) =>
Extensions.OrResult(
EnumLoader.Parse<Currency>(currency),
GeneralValidation.Value(amount),
EnumLoader.ParseAllowNull<PaymentMethod>(paymentMethod),
GeneralValidation.Parse(orderId, Id.FromInput<Order>)
).Bind((validCurrency, validAmount, validPaymentMethod, validOrderId) =>
{
... do something with valid and now typed values!
return Result<Unit>.Ok();
});
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net9.0
- DotNetThoughts.Results (>= 1.5.11)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.