SimpleEntityValidation 1.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package SimpleEntityValidation --version 1.0.1                
NuGet\Install-Package SimpleEntityValidation -Version 1.0.1                
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="SimpleEntityValidation" Version="1.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SimpleEntityValidation --version 1.0.1                
#r "nuget: SimpleEntityValidation, 1.0.1"                
#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.
// Install SimpleEntityValidation as a Cake Addin
#addin nuget:?package=SimpleEntityValidation&version=1.0.1

// Install SimpleEntityValidation as a Cake Tool
#tool nuget:?package=SimpleEntityValidation&version=1.0.1                

SimpleEntityValidation

Why?

  • Is very simple to use.
  • You create your entity/class validation and can be used in any times.
  • Whenever you need to validate a CLASS you don't need to repeat the validation.
  • You can centralize your class validations in one place.

How i do?

  • Just extend the abstraction class "AbstractValidation".
  • Use the protected method "RuleFor" to setup the especifications of your field validations.

Example

  • Client (Model)
	public class Client {
        public Guid Id { get; set; }
        public string Name { get; set; }
        public string Document { get; set; }
        public string Email { get; set; }
        public DateTime CreationDate { get; set; }
        public int YearsOld { get; set; }
        public string Password { get; set; }
        public string CheckPassword { get; set; }
        public List<string> Tags { get; set; }
    }	
  • ClientValidator (Your Client Validator)
    public class ClientValidator : AbstractValidator<Client>
    {
        public ClientValidator() 
        {
            RuleFor(x => x.Name).NotNull().MinLength(5);

            RuleFor(x => x.Password).NotNull().MustBeEqual(x => x.CheckPassword);

            RuleFor(x => x.Email).NotNull().MinLength(10);

            RuleFor(x => x.Document).MaxLength(11);

            RuleFor(x => x.Password).NotEqual("12345");

            RuleFor(x => x.YearsOld).GreaterThan(17);

            RuleFor(x => x.Tags).NotNull();

            RuleFor(x => x.YearsOld)
                .LessThan(150)
                .WithMessage("The field 'YearsOld' is not less than '150'");
        }
    }
  • Usage
    class Program
    {
        protected Program() { }

        static void Main(string[] args)
        {
            Client client = new() { Password = "12345", CheckPassword = "12312s1", YearsOld = 155 };

            ClientValidator clientValidator = new();
            
            ValidationResult result = clientValidator.Validate(client);

            if (result.ValidationFailures.Count > 0)
                Console.WriteLine("Client entity validation with errors:");

            result.ValidationFailures.ToList().ForEach(failure => Console.WriteLine($"{failure.Message}"));

            Console.ReadKey();
        }
    }
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.1

    • 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.

Version Downloads Last updated
1.1.1 473 3/27/2022
1.0.1 420 3/20/2022
1.0.0 425 3/20/2022