AnnotatedResult.AspNetCore
1.0.0-rc.3
See the version list below for details.
dotnet add package AnnotatedResult.AspNetCore --version 1.0.0-rc.3
NuGet\Install-Package AnnotatedResult.AspNetCore -Version 1.0.0-rc.3
<PackageReference Include="AnnotatedResult.AspNetCore" Version="1.0.0-rc.3" />
paket add AnnotatedResult.AspNetCore --version 1.0.0-rc.3
#r "nuget: AnnotatedResult.AspNetCore, 1.0.0-rc.3"
// Install AnnotatedResult.AspNetCore as a Cake Addin #addin nuget:?package=AnnotatedResult.AspNetCore&version=1.0.0-rc.3&prerelease // Install AnnotatedResult.AspNetCore as a Cake Tool #tool nuget:?package=AnnotatedResult.AspNetCore&version=1.0.0-rc.3&prerelease
AnnotatedResult
AnnotatedResult is a lightweight .NET model validation library utilizing System.ComponentModel.DataAnnotations
.
NuGet Package
dotnet add package AnnotatedResult --version 1.0.0-rc.3
dotnet add package AnnotatedResult.AspNetCore --version 1.0.0-rc.3
Overview
Validation
public class Request
{
[Required]
[RegularExpression(RegexPattern.Username)]
public string Username { get; init; }
[EmailAddress]
public string Email { get; init; }
[Required]
[RegularExpression(RegexPattern.StrongPassword)]
public string Password { get; init; }
}
Request
is a class with Data Annotation attribute assigned for each properties. AnnotatedResult make it so it's easy to validate.
var request = new Request();
bool isValid = request.TryValidate(out Error[] errors);
TryValidate
is an extension method use to validation any instance of object. If the object has Data Annotation attribute assigned to either field of property it will perform the validation process and return a boolean
and an out
parameter of type Error[]
.
if(!isValid)
{
Result<Request> result = Result<Request>.Invalid(errors);
return result;
}
Result<Request> result = Result<Request>.Ok(request);
return result;
Result<T>
is a generic wrapper class that encapsulate Data Annotation validation result. The example above it hold the generic type of Request
. Result<T>
can be modified whether the is a success or an error--or a specified error such as Unauthorized or NotFound.
Result<T>
with 200 status code or Ok
status return the validated object in question where as error (specified or otherwise) return list of errors.
var ok = Result<Request>.Ok(request);
var error = Result<Request>.Error(errors);
var invalid = Result<Request>.Invalid(errors);
var unauthorized = Result<Request>.Unauthorized(errors);
var forbidden = Result<Request>.Forbidden(errors);
var conflict = Result<Request>.Conflict(errors);
var notFound = Result<Request>.NotFound(errors);
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. 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. |
-
net6.0
- AnnotatedResult (>= 1.0.0-rc.3)
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 |
---|---|---|
1.0.0-rc.5 | 74 | 2/29/2024 |
1.0.0-rc.4 | 69 | 2/12/2024 |
1.0.0-rc.3 | 78 | 1/24/2024 |
1.0.0-rc.2 | 65 | 1/19/2024 |
1.0.0-rc.1 | 89 | 1/7/2024 |
1.0.0-preview.8 | 76 | 1/6/2024 |
1.0.0-preview.7 | 127 | 12/6/2023 |
1.0.0-preview.6 | 77 | 12/1/2023 |
1.0.0-preview.5 | 56 | 11/29/2023 |
1.0.0-preview.4 | 57 | 11/29/2023 |
1.0.0-preview.3 | 123 | 9/5/2022 |
1.0.0-preview.2 | 108 | 9/4/2022 |
1.0.0-preview.1 | 114 | 8/28/2022 |