PosInformatique.Foundations.People.DataAnnotations
1.1.0
Prefix Reserved
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
<PackageReference Include="PosInformatique.Foundations.People.DataAnnotations" Version="1.1.0" />
<PackageVersion Include="PosInformatique.Foundations.People.DataAnnotations" Version="1.1.0" />
<PackageReference Include="PosInformatique.Foundations.People.DataAnnotations" />
paket add PosInformatique.Foundations.People.DataAnnotations --version 1.1.0
#r "nuget: PosInformatique.Foundations.People.DataAnnotations, 1.1.0"
#:package PosInformatique.Foundations.People.DataAnnotations@1.1.0
#addin nuget:?package=PosInformatique.Foundations.People.DataAnnotations&version=1.1.0
#tool nuget:?package=PosInformatique.Foundations.People.DataAnnotations&version=1.1.0
PosInformatique.Foundations.People.DataAnnotations
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
DataAnnotationsattributes 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
FirstNameandLastNamevalue objects. - Clear and consistent error messages.
nullvalues 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
Links
| 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 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. |
-
net10.0
- PosInformatique.Foundations.People (>= 1.1.0)
-
net8.0
- PosInformatique.Foundations.People (>= 1.1.0)
-
net9.0
- PosInformatique.Foundations.People (>= 1.1.0)
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.