Myce.Validation
1.0.0
Project was completed refactored and renamed to Myce.FluentValidator
dotnet add package Myce.Validation --version 1.0.0
NuGet\Install-Package Myce.Validation -Version 1.0.0
<PackageReference Include="Myce.Validation" Version="1.0.0" />
<PackageVersion Include="Myce.Validation" Version="1.0.0" />
<PackageReference Include="Myce.Validation" />
paket add Myce.Validation --version 1.0.0
#r "nuget: Myce.Validation, 1.0.0"
#:package Myce.Validation@1.0.0
#addin nuget:?package=Myce.Validation&version=1.0.0
#tool nuget:?package=Myce.Validation&version=1.0.0
MYCE.Validation
MYCE (Makes Your Coding Easier) Validation is a fluent validation library designed to simplify entity validation in .NET applications.
Installation
Package Manager Console:
Install-Package Myce.Validation
Features
- Validator: Basic class for validation
- EntityValidator: Fluent validation class for entities
- ValidatorBuilder: Orchestrates multiple validations in a single process
Usage
1. Create your Entity
public class Person
{
public string Name { get; set; }
public int Age { get; set; }
public string Email { get; set; }
public string Code { get; set; }
}
2. Define Validation Rules
Use the EntityValidator to define rules for your entity properties.
var person = new Person { Name = "John Doe", Age = 30, Email = "john.doe@example.com", Code = "A123" };
var validator = new EntityValidator<Person>()
.RuleFor(x => x.Name)
.IsRequired()
.MinLength(3)
.MaxLength(50)
.Apply()
.RuleFor(x => x.Age)
.IsGreaterThanOrEqualTo(18)
.IsLessThanOrEqualTo(100)
.Apply()
.RuleFor(x => x.Email)
.IsRequired()
.IsValidEmailAddress()
.Apply()
.RuleFor(x => x.Code)
.ExactNumberOfCharacters(4)
.ContainsOnlyNumber()
.Apply();
var result = validator.Validate(person);
if (result.HasError)
{
foreach (var message in result.Messages)
{
Console.WriteLine(message.Text);
}
}
Supported Validators
| Validator | Description |
|---|---|
IsRequired |
Validates that the property is not null or empty. |
IsRequiredIf |
Validates that the property is required if a condition is true. |
MaxLength |
Validates the maximum length of a string. |
MaxLengthIf |
Validates maximum length if a condition is true. |
MinLength |
Validates the minimum length of a string. |
MinLengthIf |
Validates minimum length if a condition is true. |
ExactNumberOfCharacters |
Validates that a string has an exact length. |
ExactNumberOfCharactersIf |
Validates exact length if a condition is true. |
IsValidDate |
Validates that a string can be parsed as a valid date. |
IsValidEmailAddress |
Validates that a string is a valid email format. |
Contains |
Validates that the value exists within a provided collection. |
ContainsOnlyNumber |
Validates that a string contains only numeric characters. |
IsEqualTo |
Validates equality to a specific value. |
IsGreaterThan |
Validates that the value is greater than a specified value. |
IsGreaterThanOrEqualTo |
Validates that the value is greater than or equal to a specified value. |
IsLessThan |
Validates that the value is less than a specified value. |
IsLessThanOrEqualTo |
Validates that the value is less than or equal to a specified value. |
Dependencies
- Myce.Extensions
- Myce.Response
Contributions
Contributions are welcome! If you have a validation method you think is useful and can make life easier for other developers, please create a Pull Request and submit it. Attention: All submitted methods must include a unit test.
Developed by Fernando Prass
| 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. 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. |
-
net6.0
- Myce.Extensions (>= 0.2.7)
- Myce.Response (>= 0.1.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.