ISOCodex.Addressing 1.0.0-alpha.2

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

ISOCodex.Addressing

ISOCodex.Addressing provides a small .NET domain model for postal addresses plus country-specific formatting and validation.

Features

  • ISO 3166-1 alpha-2 country code value object
  • Lightweight postal code value object
  • Address model suitable for application/domain use
  • Country-specific address formatting
  • Country-specific validation via IAddressValidator
  • DI registration for selected built-in formatters and validators
  • Built-in support for:
    • Great Britain (GB)
    • United States (US)
    • Canada (CA)

Installation

dotnet add package ISOCodex.Addressing

Core types

  • Address
  • CountryCode
  • PostalCode
  • IAddressFormatter
  • AddressValidationResult
  • AddressValidationIssue
  • IAddressValidator
  • IAddressValidatorFactory

Register country services with DI

using ISOCodex.Addressing;
using ISOCodex.Addressing.Formatting;
using ISOCodex.Addressing.Validation;
using Microsoft.Extensions.DependencyInjection;

var services = new ServiceCollection();

services.AddAddressing(
    CountryCode.GB,
    CountryCode.US,
    CountryCode.CA);

using var serviceProvider = services.BuildServiceProvider();

var validatorFactory = serviceProvider.GetRequiredService<IAddressValidatorFactory>();
var formatter = serviceProvider.GetRequiredService<IAddressFormatter>();

AddAddressing(...) registers both the formatter and validator for each requested built-in country.

Validate an address

using ISOCodex.Addressing;

var address = new Address(
    line1: "10 Downing Street",
    line2: null,
    city: "London",
    stateOrProvince: null,
    postalCode: new PostalCode("SW1A 2AA"),
    countryCode: CountryCode.GB);

var result = validatorFactory
    .GetValidator(address.CountryCode)
    .Validate(address);

if (!result.IsValid)
{
    foreach (var issue in result.Issues)
    {
        Console.WriteLine(issue.Code);
        Console.WriteLine(issue.PropertyName);
        Console.WriteLine(issue.Message);
    }
}

Validate(...) does not throw for ordinary validation failures. It returns structured issue data for APIs, forms, imports, and other user-facing workflows.

AddressValidationResult contains:

  • IsValid - true when no issues were found
  • Issues - a list of AddressValidationIssue

Each AddressValidationIssue contains:

  • Code - stable machine-readable issue code, for example Address.PostalCode.Invalid
  • Message - human-readable description
  • PropertyName - related Address property when applicable

Built-in validators collect multiple issues where possible.

Format an address

using ISOCodex.Addressing.Formatting;

var formatted = formatter.Format(address);

Default output is multi-line and includes the country. For a GB address:

10 Downing Street
London
SW1A 2AA
United Kingdom

The formatter uses Address.CountryCode to choose the correct country-specific formatter. That lets application code stay simple while each formatter owns its country's postal layout.

The built-in countries currently format as:

GB
10 Downing Street
London
SW1A 2AA
United Kingdom

US
1600 Pennsylvania Avenue NW
Washington, DC 20500
United States

CA
111 Wellington Street
Ottawa ON K1A 0A9
Canada

Country names are currently emitted as English display names: United Kingdom, United States, Canada, and country names supplied by extension packages. Localization and alternate country-name output can be added later without changing the core routing model.

Single-line formatting

Single-line output is useful for grids, autocomplete results, logs, exports, and other compact displays:

var singleLine = formatter.Format(
    address,
    new AddressFormatOptions
    {
        Style = AddressFormatStyle.SingleLine
    });

Output:

10 Downing Street, London, SW1A 2AA, United Kingdom

You can also choose a different separator:

var pipeSeparated = formatter.Format(
    address,
    new AddressFormatOptions
    {
        Style = AddressFormatStyle.SingleLine,
        SingleLineSeparator = " | "
    });

AddressFormatOptions is mutable by design for straightforward call-site configuration:

var options = new AddressFormatOptions
{
    Style = AddressFormatStyle.SingleLine,
    IncludeCountry = false
};

Omitting the country

When the country is already shown elsewhere in your UI or data export, omit the country line:

var localOnly = formatter.Format(
    address,
    new AddressFormatOptions
    {
        IncludeCountry = false
    });

Output:

10 Downing Street
London
SW1A 2AA

Custom country formatters

Extension packages and applications can register additional country formatters:

services.AddAddressFormatter(
    CountryCode.ES,
    () => new MySpanishAddressFormatter());

Custom formatters implement ICountryAddressFormatter. IAddressFormatter remains the single service consumers use to format any registered country.

Country-specific notes

Great Britain (GB)

  • Validates postcode format
  • Expects uppercase postcode format with a space, for example SW1A 1AA

United States (US)

  • Validates ZIP or ZIP+4
  • Requires StateOrProvince
  • Accepts US state and territory abbreviations

Canada (CA)

  • Validates postal code format such as A1A 1A1
  • Province/territory is optional
  • If provided, province/territory must be a valid abbreviation

Extension packages

Country support can be extended through additional packages. Spain support is provided by the separate ISOCodex.Addressing.Spain project in the repository rather than by this core package.

Important behaviour

  • PostalCode itself does not enforce country-specific formatting
  • Validation is performed by the country validator
  • Formatting is performed by the country formatter registered for Address.CountryCode
  • Formatting does not mutate the address
  • Formatting does not validate the address or prove that it exists
  • Built-in country names are currently English display names
  • Validators normalize common postal-code casing and spacing for validation without changing the stored PostalCode.Code
  • AddAddressing(...) only registers the built-in countries you explicitly request

License

MIT

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (12)

Showing the top 5 NuGet packages that depend on ISOCodex.Addressing:

Package Downloads
ISOCodex.Addressing.Spain

Spain-specific extension package for ISOCodex.Addressing.

ISOCodex.Addressing.France

France-specific extension package for ISOCodex.Addressing.

ISOCodex.Addressing.Ireland

Ireland-specific extension package for ISOCodex.Addressing.

ISOCodex.Currency.Addressing

Address and currency validation helpers for ISOCodex.Currency and ISOCodex.Addressing.

ISOCodex.Addressing.Canada

Canada-specific extension package for ISOCodex.Addressing.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.1 499 6/23/2026
2.0.0 567 6/23/2026
2.0.0-alpha 465 6/20/2026
1.3.0 634 6/20/2026
1.2.0 327 6/14/2026
1.1.0 224 6/14/2026
1.0.0 139 6/14/2026
1.0.0-alpha.4 72 6/14/2026
1.0.0-alpha.3 64 6/13/2026
1.0.0-alpha.2 67 6/13/2026
1.0.0-alpha.1 70 6/13/2026