RecordValidator 1.1.0
See the version list below for details.
dotnet add package RecordValidator --version 1.1.0
NuGet\Install-Package RecordValidator -Version 1.1.0
<PackageReference Include="RecordValidator" Version="1.1.0" />
paket add RecordValidator --version 1.1.0
#r "nuget: RecordValidator, 1.1.0"
// Install RecordValidator as a Cake Addin #addin nuget:?package=RecordValidator&version=1.1.0 // Install RecordValidator as a Cake Tool #tool nuget:?package=RecordValidator&version=1.1.0
RecordValidator
RecordValidator is a .NET library for validating records against predefined rules.
Installation
You can install RecordValidator via NuGet Package Manager Console by running:
Install-Package RecordValidator
Or, you can install it using the .NET CLI:
dotnet add package RecordValidator
Define the rule for the properties for the class
public class Student{
[Mandatory(validateForDefaultValue:true)]
public int Id { get; set; }
[Mandatory]
public string Name { get; set; }
[Mandatory(errorMessage:"Email is mandatory")]
[Email]
public string Email { get; set; }
[Date(minDate:"2000-01-01")]
public DateTime Doj { get; set; }
[Mandatory]
[RegularExpression(pattern: "^(?:(?:\\+|0{0,2})91(\\s*[\\-]\\s*)?|[0]?)?[6789]\\d{9}$")]
public string Mobile { get; set; }
public bool IActive { get; set; }
[Length(min:10, max:100)]
public string Address { get; set; }
[RegularExpression(pattern: "^[1-9][0-9]{5}$")]
public string Pincode { get; set; }
}
Now call the ValidateValueAndThrowException function
try
{
var std=new Student()
{
Name="",
Address="TH",
Doj=new DateTime(1999,01,01),
Email="Vishal",
IActive=true,
Id=0,
Mobile="3949132",
Pincode="0002345"
};
std.ValidateValueAndThrowException();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
Or you can use ValidateValueAndReturnListOfExceptions() to get the exceptions in case if you don't want to break your flow
try
{
var std=new Student()
{
Name="",
Address="TH",
Doj=new DateTime(1999,01,01),
Email="Vishal",
IActive=true,
Id=0,
Mobile="3949132",
Pincode="0002345"
};
var result=std.ValidateValueAndReturnListOfExceptions();
//you can now use the list to log the errors
foreach(var exception in result)
{
Console.WriteLine($"Error - {exception.ErrorMessage} against {exception.Param}");
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
New Changes in 1.1.0
- bug fixes
Features
- Support for various validation rules and will be added more in coming versions.
- Easy to add in the project and can be easily added in existing project.
- Custom error message can be set if not given then default will be taken.
License
This project is licensed under the MIT License - see the LICENSE file for details.
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. |
-
net6.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.