Validity.DataAnnotation
2.1.3
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package Validity.DataAnnotation --version 2.1.3
NuGet\Install-Package Validity.DataAnnotation -Version 2.1.3
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="Validity.DataAnnotation" Version="2.1.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Validity.DataAnnotation" Version="2.1.3" />
<PackageReference Include="Validity.DataAnnotation" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Validity.DataAnnotation --version 2.1.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Validity.DataAnnotation, 2.1.3"
#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.
#:package Validity.DataAnnotation@2.1.3
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Validity.DataAnnotation&version=2.1.3
#tool nuget:?package=Validity.DataAnnotation&version=2.1.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Table of content
Installation
dotnet add package Resulver
Usage
public Result<int> Sum(int a, int b)
{
var sum = a + b;
return new Result<int>(sum);
}
public void Writer()
{
var result = Sum(3, 5);
Console.WriteLine(result.Content);
}
Result Message
public Result<User> AddUser(User user)
{
// implementation
return new Result<User>(user, message: "User Created");
}
public void Writer()
{
var user = new User();
var result = AddUser(user);
Console.WriteLine(result.Message);
}
Result Errors
public class UserNotFoundError() : ResultError(message: "User not found");
public class UserIdIsNotValidError() : ResultError(message: "User ID is not valid");
public Result RemoveUser(int userId)
{
//Implementation
return new UserNotFoundError();
//or for multiple errors
return new Result(new UserNotFoundError(), new UserIdIsNotValidError());
}
public void Writer()
{
var result = RemoveUser(1);
if (result.IsFailure)
{
foreach (var error in result.Errors)
{
Console.WriteLine(error.Message);
}
}
}
1. Install package
dotnet add package AutoValidator.DataAnnotation
2. Create Class
public class MyClass
{
[Phone]
public string PhoneNumber { get; set; }
public NestedClass Nested { get; set; }
}
public class NestedClass
{
[MaxLength(5)]
public string Title { get; set; }
}
3. Add validator to service container
in Program.cs
builder.Services.AddObjectValidator();
4. Inject validator to yout controller
[ApiController]
[Route("api/[controller]")]
public class MyController : ControllerBase
{
readonly IObjectValidator _validator;
public MyController(IObjectValidator validator)
{
_validator = validator;
}
}
5. Use validator
[HttpPost]
public IActionResult AddUser(MyClass myClass)
{
var validationErrors = _validator.Validate(myClass);
if (validationErrors.Count != 0)
{
//DO SOMETHING
}
}
| 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. net9.0 was computed. 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. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- Microsoft.Extensions.Localization (>= 8.0.6)
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.2.3 | 176 | 10/3/2024 |
| 2.2.2 | 197 | 8/20/2024 |
| 2.2.1 | 170 | 8/20/2024 |
| 2.1.12 | 183 | 8/17/2024 |
| 2.1.11 | 170 | 8/17/2024 |
| 2.1.3 | 168 | 8/20/2024 |
| 2.1.2 | 165 | 8/20/2024 |
| 2.1.1 | 175 | 7/14/2024 |
| 2.1.0 | 161 | 7/13/2024 |
| 2.0.1 | 173 | 7/7/2024 |
| 2.0.0 | 170 | 7/7/2024 |
| 1.3.0 | 164 | 7/3/2024 |
| 1.2.0 | 175 | 6/28/2024 |
| 1.0.0 | 157 | 6/12/2024 |