DynamicVNET is a .NET Standard library that was created to develop dynamic reuse validation. The main idea of the library is to apply validation rules using a declarative approach. And the rules can be used on POCO and BlackBox libraries. Also, it has rich facilities and features as Fluent API at runtime.
License
—
Deps
3
Install Size
—
Vulns
✓ 0
Published
Oct 31, 2024
$ dotnet add package DynamicVNETDynamicVNET is .NET Standard library that was created help to develop reuse dynamic validation. It helps to build some rules on POCO and own blackbox libs. It has rich conveniences and features as a Fluent API in runtime, wrapped over DataAnnotation attributes and supports a cross-platform environment.
POCO Models.
public class Employee
{
public string Name { get; set; }
public Token TokenNumber { get; set; }
public string Email { get; set; }
}
public class Token
{
public string Number { get; set; }
}
Validation.
Employee emp = new Employee()
{
Name = "Jhon",
TokenNumber = new Token() { Number = "2312412312341" },
Email = "jhon.sim@gmail.com"
};
var validator = ValidatorFactory.Create<Employee>(builder => {
builder.Marker
.StringLen(x => x.Name, 4)
.EmailAddress(x => x.Email)
.Predicate(x => x.Email.Contains("@simple.com"))
.Required(x => x.TokenNumber.Number) // nested member
.Required(x => x.TokenNumber.Number); // automatic ignored
});
bool result = validator.IsValid(emp);
// Detailed Result
IEnumerable<ValidationMarkerResult> results = validator.Validate(emp); var validator = ValidatorFactory.Create<Model>(builder => {
builder.Marker
.Required(x => x.Token.TokenNumber)
.Branch(x => x.Name.Contains("resul"), x =>
{
x.Required(y => y.Email)
.StringLen(y => y.Email, 2)
.Branch(n => n.Name.Length >= 4,n => {
n.MaxLen(s => s.Token.TokenNumber, length: 4);
});
}).Branch(x => x.Email.Contains("aa"), x =>
{
x.Required(y => y.Name)
.StringLen(y => y.Name, 5)
.StringLen(y => y.Token.TokenNumber, 9);
});
});public class EmployeeValidator : BaseValidator<Employee>
{
protected override void Setup(ValidatorBuilder<Employee> builder)
{
builder.Marker
.For(x => x.Name)
.Required();
builder.Marker
.Branch(x => x.Name.Contains("jhon"), x =>
{
x.MaxLen(m => m.TokenNumber.Number, 15);
})
.For(x => x.Email)
.Required()
.EmailAddress();
builder.Marker
.Required(x => x.TokenNumber.Number);
}
}
Employee emp = new Employee()
{
Name = "selman:okkes",
TokenNumber = new Token() { Number = "adasd123123asd" },
Email = "jhon.sim@jhona.com"
};
var empValidator = new EmployeeValidator();
bool result = empValidator.IsValid(emp);Install DynamicVNET from the package manager console:
PM> Install-Package DynamicVNET -Version 1.4.0
DynamicVNET is Copyright © 2018 Rasul Huseynov.