PosInformatique.Foundations.EmailAddresses
1.0.0-alpha.4
Prefix Reserved
dotnet add package PosInformatique.Foundations.EmailAddresses --version 1.0.0-alpha.4
NuGet\Install-Package PosInformatique.Foundations.EmailAddresses -Version 1.0.0-alpha.4
<PackageReference Include="PosInformatique.Foundations.EmailAddresses" Version="1.0.0-alpha.4" />
<PackageVersion Include="PosInformatique.Foundations.EmailAddresses" Version="1.0.0-alpha.4" />
<PackageReference Include="PosInformatique.Foundations.EmailAddresses" />
paket add PosInformatique.Foundations.EmailAddresses --version 1.0.0-alpha.4
#r "nuget: PosInformatique.Foundations.EmailAddresses, 1.0.0-alpha.4"
#:package PosInformatique.Foundations.EmailAddresses@1.0.0-alpha.4
#addin nuget:?package=PosInformatique.Foundations.EmailAddresses&version=1.0.0-alpha.4&prerelease
#tool nuget:?package=PosInformatique.Foundations.EmailAddresses&version=1.0.0-alpha.4&prerelease
PosInformatique.Foundations.EmailAddresses
Introduction
This package provides a strongly-typed EmailAddress value object that ensures only valid email addresses (RFC 5322 compliant) can be instantiated.
It simplifies validation, parsing, comparison, and string formatting of email addresses.
Install
You can install the package from NuGet:
dotnet add package PosInformatique.Foundations.EmailAddresses
Features
- Strongly-typed email address validation and parsing
- Ensures email addresses are formatted according to RFC 5322
- Email values are always stored and compared in lowercase to avoid case-sensitive inconsistencies
- Implements
IEquatable<T>
,IComparable<T>
, and operator overloads for equality and ordering - Provides
IFormattable
andIParsable<T>
for seamless integration with .NET APIs - Implicit conversion between
string
andEmailAddress
Use cases
- Validation: prevent invalid emails from being stored in your domain entities.
- Type safety: avoid dealing with raw strings when working with email addresses.
- Conversion: use implicit/explicit parsing and formatting seamlessly when working with APIs.
- Consistency: ensures a single, robust email parsing logic across all projects.
Examples
Create and validate email addresses
// Implicit conversion from string
EmailAddress email = "john.doe@example.com";
// Access parts
Console.WriteLine(email.UserName); // "john.doe"
Console.WriteLine(email.Domain); // "example.com"
// Validation
bool valid = EmailAddress.IsValid("test@domain.com"); // true
bool invalid = EmailAddress.IsValid("not-an-email"); // false
Parsing
var email = EmailAddress.Parse("alice@company.org");
Console.WriteLine(email); // "alice@company.org"
if (EmailAddress.TryParse("bob@company.org", out var parsed))
{
Console.WriteLine(parsed.Domain); // "company.org"
}
Comparisons
var a = (EmailAddress)"alice@company.com";
var b = (EmailAddress)"bob@company.com";
Console.WriteLine(a == b); // false
Console.WriteLine(a != b); // true
Console.WriteLine(a < b); // true, alphabetic order
var list = new List<EmailAddress> { b, a };
list.Sort(); // Sorted alphabetically
Links
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | 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 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. |
-
net9.0
- MimeKitLite (>= 4.13.0)
NuGet packages (3)
Showing the top 3 NuGet packages that depend on PosInformatique.Foundations.EmailAddresses:
Package | Downloads |
---|---|
PosInformatique.Foundations.EmailAddresses.Json
Provides a System.Text.Json converter for the EmailAddress value object. Enables seamless serialization and deserialization of RFC 5322 compliant email addresses within JSON documents. Designed to integrate smoothly with System.Text.Json options, ensuring consistent validation and parsing during JSON processing. |
|
PosInformatique.Foundations.EmailAddresses.EntityFramework
Provides Entity Framework Core integration for the EmailAddress value object. Enables seamless mapping of RFC 5322 compliant email addresses as strongly-typed properties in Entity Framework Core entities, with safe conversion to string. |
|
PosInformatique.Foundations.EmailAddresses.FluentValidation
Provides a FluentValidation extension to validate email addresses using the strongly-typed EmailAddress value object (RFC 5322 compliant). |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
1.0.0-alpha.4 | 37 | 9/27/2025 |
1.0.0-alpha.3 | 70 | 9/26/2025 |
1.0.0-alpha.2 | 68 | 9/26/2025 |
1.0.0-alpha.1 | 106 | 9/25/2025 |
1.0.0
- Initial release with strongly-typed EmailAddress value object.