JAAvila.FluentOperations.DataAnnotations
1.5.0
dotnet add package JAAvila.FluentOperations.DataAnnotations --version 1.5.0
NuGet\Install-Package JAAvila.FluentOperations.DataAnnotations -Version 1.5.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="JAAvila.FluentOperations.DataAnnotations" Version="1.5.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="JAAvila.FluentOperations.DataAnnotations" Version="1.5.0" />
<PackageReference Include="JAAvila.FluentOperations.DataAnnotations" />
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 JAAvila.FluentOperations.DataAnnotations --version 1.5.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: JAAvila.FluentOperations.DataAnnotations, 1.5.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 JAAvila.FluentOperations.DataAnnotations@1.5.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=JAAvila.FluentOperations.DataAnnotations&version=1.5.0
#tool nuget:?package=JAAvila.FluentOperations.DataAnnotations&version=1.5.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
JAAvila.FluentOperations.DataAnnotations
Automatically generates JAAvila.FluentOperations Quality Blueprint validation rules from System.ComponentModel.DataAnnotations attributes.
Installation
dotnet add package JAAvila.FluentOperations.DataAnnotations
Quick Start
Fully automatic blueprint
var blueprint = DataAnnotationsBlueprint<User>.FromAnnotations();
var report = blueprint.Check(user);
if (!report.IsValid)
{
foreach (var failure in report.Failures)
Console.WriteLine(failure);
}
Hybrid blueprint — annotations + custom rules
public class UserBlueprint : DataAnnotationsBlueprint<User>
{
public UserBlueprint()
{
using (Define())
{
// All [Required], [EmailAddress], etc. rules are generated automatically:
IncludeAnnotations();
// Add extra rules that have no DataAnnotation equivalent:
For(x => x.Username).Test().NotBeNull().HaveMinLength(3).HaveMaxLength(20);
}
}
}
Dependency Injection
// Program.cs / Startup.cs
services.AddDataAnnotationsBlueprint<User>();
// Inject and use:
public class UserService(DataAnnotationsBlueprint<User> blueprint)
{
public void Validate(User user)
{
var report = blueprint.Check(user);
// ...
}
}
Attribute Mapping Table
| DataAnnotations Attribute | Generated Operation |
|---|---|
[Required] on string |
.NotBeNull().NotBeEmpty() |
[Required] on other types |
.NotBeNull() |
[StringLength(max)] |
.HaveMaxLength(max) |
[StringLength(max, MinimumLength = min)] |
.HaveLengthBetween(min, max) |
[MinLength(n)] |
.HaveMinLength(n) |
[MaxLength(n)] |
.HaveMaxLength(n) |
[Range(min, max)] |
.BeInRange(min, max) |
[EmailAddress] |
.BeEmail() |
[Url] |
.BeUrl() |
[RegularExpression(pattern)] |
.Match(pattern) |
[Phone] |
.Match(phoneRegex) |
[CreditCard] |
.BeCreditCard() |
Supported property types for [Range]: int, int?, long, long?, double, double?, decimal, decimal?.
AnnotationOptions
var options = new AnnotationOptions
{
DefaultSeverity = Severity.Warning, // Default: Severity.Error
ErrorCodePrefix = "USER", // Default: null (no error code)
IgnoreRequired = true, // Default: false
UseAnnotationErrorMessages = false, // Default: true
ExcludedProperties = { "InternalId" }, // Default: empty
IncludeInheritedProperties = false // Default: true
};
var blueprint = DataAnnotationsBlueprint<User>.FromAnnotations(options);
License
Apache-2.0
| Product | Versions 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.
-
net8.0
- JAAvila.FluentOperations (>= 1.5.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 6.0.0)
- System.ComponentModel.Annotations (>= 5.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.