PosInformatique.Foundations.People.DataAnnotations 1.1.0

Prefix Reserved
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package PosInformatique.Foundations.People.DataAnnotations --version 1.1.0
                    
NuGet\Install-Package PosInformatique.Foundations.People.DataAnnotations -Version 1.1.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="PosInformatique.Foundations.People.DataAnnotations" Version="1.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="PosInformatique.Foundations.People.DataAnnotations" Version="1.1.0" />
                    
Directory.Packages.props
<PackageReference Include="PosInformatique.Foundations.People.DataAnnotations" />
                    
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 PosInformatique.Foundations.People.DataAnnotations --version 1.1.0
                    
#r "nuget: PosInformatique.Foundations.People.DataAnnotations, 1.1.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 PosInformatique.Foundations.People.DataAnnotations@1.1.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=PosInformatique.Foundations.People.DataAnnotations&version=1.1.0
                    
Install as a Cake Addin
#tool nuget:?package=PosInformatique.Foundations.People.DataAnnotations&version=1.1.0
                    
Install as a Cake Tool

PosInformatique.Foundations.People.DataAnnotations

NuGet version NuGet downloads

Introduction

This package provides .NET DataAnnotations attributes to validate first names and last names using the FirstName and LastName value objects from PosInformatique.Foundations.People.

It allows you to apply robust name validation directly on your models with attributes like [FirstName] attribute and [LastName], ensuring that string properties conform to the business rules for first and last names.

Install

You can install the package from NuGet:

dotnet add package PosInformatique.Foundations.People.DataAnnotations

Features

  • DataAnnotations attributes for first name and last name validation based on the business rules of the PosInformatique.Foundations.People package.
  • Uses the same parsing and validation rules as the FirstName and LastName value objects.
  • Clear and consistent error messages.

null values are accepted (combine with [Required] attribute to forbid nulls).

Examples

Validating FirstName

using System.ComponentModel.DataAnnotations;
using PosInformatique.Foundations.People.DataAnnotations;

public class Person
{
    // FirstName must be a valid FirstName (e.g., "John", "Jean-Pierre")
    // Null values are allowed by default. Use [Required] to disallow.
    [FirstName]
    public string? FirstName { get; set; }

    public string? LastName { get; set; }
}

// Usage
var person1 = new Person { FirstName = "John", LastName = "DOE" };
var context = new ValidationContext(person1);
var results = new List<ValidationResult>();
var isValid1 = Validator.TryValidateObject(person1, context, results, validateAllProperties: true); // true

var person2 = new Person { FirstName = "John_123", LastName = "DOE" };
context = new ValidationContext(person2);
results = new List<ValidationResult>();
var isValid2 = Validator.TryValidateObject(person2, context, results, validateAllProperties: true); // false

var person3 = new Person { FirstName = new string('A', 51), LastName = "DOE" };
context = new ValidationContext(person3);
results = new List<ValidationResult>();
var isValid3 = Validator.TryValidateObject(person3, context, results, validateAllProperties: true); // false

// Null (valid by default for [FirstName])
var person4 = new Person { FirstName = null, LastName = "DOE" };
context = new ValidationContext(person4);
results = new List<ValidationResult>();
var isValid4 = Validator.TryValidateObject(person4, context, results, validateAllProperties: true); // true

// Null (invalid if [Required] is used)
public class PersonRequiredFirstName
{
    [Required]
    [FirstName]
    public string? FirstName { get; set; }
}

var person5 = new PersonRequiredFirstName { FirstName = null };
context = new ValidationContext(person5);
results = new List<ValidationResult>();
var isValid5 = Validator.TryValidateObject(person5, context, results, validateAllProperties: true); // false

Validating LastName

using System.ComponentModel.DataAnnotations;
using PosInformatique.Foundations.People.DataAnnotations;

public class Person
{
    public string? FirstName { get; set; }

    // LastName must be a valid LastName (e.g., "DOE", "SMITH-JOHNSON")
    // Null values are allowed by default. Use [Required] to disallow.
    [LastName]
    public string? LastName { get; set; }
}

// Usage
var person1 = new Person { FirstName = "John", LastName = "DOE" };
var context = new ValidationContext(person1);
var results = new List<ValidationResult>();
var isValid1 = Validator.TryValidateObject(person1, context, results, validateAllProperties: true); // true

var person2 = new Person { FirstName = "John", LastName = "DOE_123" };
context = new ValidationContext(person2);
results = new List<ValidationResult>();
var isValid2 = Validator.TryValidateObject(person2, context, results, validateAllProperties: true); // false

var person3 = new Person { FirstName = "John", LastName = new string('A', 51) };
context = new ValidationContext(person3);
results = new List<ValidationResult>();
var isValid3 = Validator.TryValidateObject(person3, context, results, validateAllProperties: true); // false

// Null (valid by default for [LastName])
var person4 = new Person { FirstName = "John", LastName = null };
context = new ValidationContext(person4);
results = new List<ValidationResult>();
var isValid4 = Validator.TryValidateObject(person4, context, results, validateAllProperties: true); // true

// Null (invalid if [Required] is used)
public class PersonRequiredLastName
{
    public string? FirstName { get; set; }

    [Required]
    [LastName]
    public string? LastName { get; set; }
}

var person5 = new PersonRequiredLastName { FirstName = "John", LastName = null };
context = new ValidationContext(person5);
results = new List<ValidationResult>();
var isValid5 = Validator.TryValidateObject(person5, context, results, validateAllProperties: true); // false
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 is compatible.  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 is compatible.  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.2.0-rc.1 50 3/31/2026
1.1.0 92 3/30/2026
1.1.0-rc.3 48 3/27/2026
1.1.0-rc.2 63 1/26/2026
1.1.0-rc.1 64 1/23/2026
1.0.0 440 11/19/2025
1.0.0-rc.4 374 11/19/2025
1.0.0-rc.3 383 11/18/2025
1.0.0-rc.2 379 11/18/2025
1.0.0-rc.1 376 11/18/2025

1.0.0
 - Initial release with the support Data Annotations for the validation of FirstName and LastName value objects.