Manik.FluentValidationExtensions 1.0.0

dotnet add package Manik.FluentValidationExtensions --version 1.0.0
                    
NuGet\Install-Package Manik.FluentValidationExtensions -Version 1.0.0
                    
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="Manik.FluentValidationExtensions" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Manik.FluentValidationExtensions" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Manik.FluentValidationExtensions" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Manik.FluentValidationExtensions --version 1.0.0
                    
#r "nuget: Manik.FluentValidationExtensions, 1.0.0"
                    
#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.
#:package Manik.FluentValidationExtensions@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Manik.FluentValidationExtensions&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Manik.FluentValidationExtensions&version=1.0.0
                    
Install as a Cake Tool

FluentValidationExtensions A reusable C# library that extends FluentValidation by providing an extension method to convert ValidationResult errors to a dictionary. This helps developers easily access validation error details in a structured format, making it easier to work with validation errors across multiple projects.

Features Convert ValidationResult errors to a dictionary: Easily access validation errors in a dictionary format. Reusable across multiple projects: Package designed to be reusable across different .NET applications. Built with FluentValidation: The extension works with FluentValidation, a popular .NET validation library. Prerequisites .NET 8.0 or later FluentValidation (version 9.x or higher) Installation You can install this package via NuGet. Use the following command to add it to your project:

bash Copy code dotnet add package FluentValidationExtensions --version 1.0.0 Alternatively, you can search for the package in NuGet.org and install it through Visual Studio’s NuGet Package Manager.

Usage Once installed, you can easily convert the ValidationResult errors into a dictionary for better manipulation or display.

Example Usage Here’s an example demonstrating how to use the ValidationResultExtensions class.

Add FluentValidation to your project: bash Copy code dotnet add package FluentValidation Define a validator for your model: csharp Copy code using FluentValidation;

public class Person { public string Name { get; set; } public int Age { get; set; } }

public class PersonValidator : AbstractValidator<Person> { public PersonValidator() { RuleFor(x ⇒ x.Name).NotEmpty().WithMessage("Name cannot be empty."); RuleFor(x ⇒ x.Age).GreaterThan(0).WithMessage("Age must be greater than 0."); } } Using ValidationResultExtensions to convert errors to a dictionary: csharp Copy code using FluentValidation; using FluentValidation.Results; using FluentValidationExtensions; // Import the extension namespace

public class Example { public static void Main() { var person = new Person { Name = string.Empty, Age = -1 };

    var validator = new PersonValidator();
    ValidationResult result = validator.Validate(person);

    // Convert ValidationResult errors to a dictionary
    var errors = result.ToDictionary();

    // Print the dictionary
    foreach (var error in errors)
    {
        Console.WriteLine($"{error.Key}: {error.Value}");
    }
}

} Example Output: plaintext Copy code Name: Name cannot be empty. Age: Age must be greater than 0. ValidationResultExtensions The extension method ToDictionary() is added to ValidationResult to help convert validation errors to a dictionary format:

csharp Copy code public static class ValidationResultExtensions { public static Dictionary<string, string> ToDictionary(this ValidationResult validationResult) { return validationResult.Errors.ToDictionary( error ⇒ error.PropertyName, error ⇒ error.ErrorMessage ); } } This method converts the list of validation errors in ValidationResult into a dictionary where the key is the property name and the value is the error message.

Contributing If you'd like to contribute to this project, feel free to fork the repository, make changes, and submit a pull request. You can also open issues if you encounter bugs or have feature requests.

Steps to contribute: Fork the repository. Create a new branch for your changes. Make your changes and write tests to cover them. Ensure the project builds and passes tests. Submit a pull request with a clear explanation of your changes. License This project is licensed under the MIT License - see the LICENSE file for details.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.0.0 175 12/31/2024