BeSwarm.Validator 1.0.1

The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. Prefix Reserved
dotnet add package BeSwarm.Validator --version 1.0.1
NuGet\Install-Package BeSwarm.Validator -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="BeSwarm.Validator" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add BeSwarm.Validator --version 1.0.1
#r "nuget: BeSwarm.Validator, 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 BeSwarm.Validator as a Cake Addin
#addin nuget:?package=BeSwarm.Validator&version=1.0.1

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

Validator

NuGet NuGet

Perform recursive localized DataAnnotations Attribute validation on your models and fluent validations.

Provide BlazorValidator for Blazor apps.

DataAnnotation Attribute validated

  • [Required]
  • [Range]
  • [MaxLength]
  • [MinLength]
  • [StringLength]

Sample usage

public class Model
{
    [Required]
    [MaxLength(6)]
    public string Name { get; set; }
}

class Program
{


    public static async Task Main(string[] args)
    {

        Model t= new();
        ValidateContext context = new ValidateContext(false);
        var listvalidationfailure = await Validate.ValidateObject(t, context);

        foreach (var item in listvalidationfailure)
        {
           Console.WriteLine($"*** error **** Field: {item.PropertyName} value={item.Obj} attribute:{item.AttributeType} message:{item.ErrorMessage}");
        }
        t.Name = "11";
        listvalidationfailure = await Validate.ValidateObject(t, context);
        foreach (var item in listvalidationfailure)
        {
            Console.WriteLine($"*** error **** Field: {item.PropertyName} value={item.Obj} attribute:{item.AttributeType} message:{item.ErrorMessage}");
        }
        t.Name = "LPLOKUAAA";
        listvalidationfailure = await Validate.ValidateObject(t, context);
        foreach (var item in listvalidationfailure)
        {
            Console.WriteLine($"*** error **** Field: {item.PropertyName} value={item.Obj} attribute:{item.AttributeType} message:{item.ErrorMessage}");
        }
		Console.ReadKey();
    }
}

Get attribute on property if exist

ex: check if [Required] is present on a property

   RequiredAttribute? ra=Validate.GetAttributeIfExist<RequiredAttribute>(t, nameof(t.Name));

Using with blazor

<EditForm Model="@_model" OnValidSubmit="@SubmitValidForm">
	<BeSwarm.Validator.BlazorValidator @ref="_BlazorValidationValidator" ValidateContext="mycontext" />

Add Fluent validation

Create au fluent class

 public class FluentValidatorModel : AbstractValidator<Model>
 {
	public FluentValidatorModel()
	{
			RuleFor(x => x.Name).NotEmpty().WithMessage("controlled by fluent: not empty");
	}
 }
 // add fluent validator
 FluentValidatorModel fv = new();
 context.FluentValidator = fv;
 listvalidationfailure = await Validate.ValidateObject(t, context);
 foreach (var item in listvalidationfailure)
 {
   Console.WriteLine($"*** error **** Field: {item.PropertyName} value={item.Obj} attribute:{item.AttributeType} message:{item.ErrorMessage}");
 }

you can also add a Fluent validation strategy

public class FluentValidatorModel : AbstractValidator<Model>
{
	public FluentValidatorModel()
	{
		RuleSet("FilterName", () =>
		{
			RuleFor(x => x.Name).NotEmpty().WithMessage("controlled by fluent: not empty");
		});
	}
}
Action<ValidationStrategy<object>> strategy = new(options => options.IncludeRuleSets("FilterName"));
context.FluentStrategy = strategy;

Company

Be Swarm https://beswarm.fr/developpeur_en/

Author

thierry roustan

License

MIT

Versions

  • 1.0.0
    • Initial release

Documentation

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on BeSwarm.Validator:

Package Downloads
BeSwarm.CoreBlazorApp The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

Package Description

BeSwarm.CoreWebApi The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.1 782 11/17/2022
1.0.0-rc1 564 10/20/2022