Iso3166Extensions Class
Definition
Namespace: DataStandardizer.Geography
Extension methods that read the metadata attached to the ISO 3166-1 country code enums and the ISO 3166-2 subdivision code struct.
public static class Iso3166Extensions
Remarks
Each accessor reads the relevant attribute applied to the enum member or subdivision field and returns the requested metadata, or null/false when it is unavailable or the code is undefined. The ISO 3166-1 accessors (GetEnglishName, GetNativeName, IsIndependent) each exist as an overload extending both Iso3166Part1Alpha2Country and Iso3166Part1Alpha3Country.
On .NET Standard targets the string? return and parameter types are string annotated with System.Diagnostics.CodeAnalysis attributes such as [MaybeNull] and [DisallowNull]. A project gets null warnings from them only on C# 8 or later with nullable enabled.
Methods
Extension
| Method | Extends | Returns | Notes |
|---|---|---|---|
GetEnglishName(Iso3166CountryName nameType) | Iso3166Part1Alpha2Country / Iso3166Part1Alpha3Country | string? | English name in the requested form. |
GetNativeName(string iso639LanguageCode, Iso3166CountryName nameType) | Iso3166Part1Alpha2Country / Iso3166Part1Alpha3Country | string? | Native name in the requested language and form. |
GetSubdivisionCategoryIdentifier() | Iso3166Part2Subdivision | ushort? | Identifier of the subdivision’s category. |
GetSubdivisionCategoryName(string iso639LanguageCode) | Iso3166Part2Subdivision | string? | Category name in the requested language. |
GetSubdivisionCategoryNamePlural(string iso639LanguageCode) | Iso3166Part2Subdivision | string? | Plural form of the category name. |
GetSubdivisionCode() | Iso3166Part2Subdivision | string? | The ISO 3166-2 code (e.g. AU-NT). |
GetSubdivisionNativeName(string iso639LanguageCode, string? romanizationSystem = null) | Iso3166Part2Subdivision | string? | Native name of the subdivision. With no romanizationSystem, when the language has several names, the one ISO 3166-2 lists first. |
GetSubdivisionNativeNameLocalVariant(string iso639LanguageCode, string? romanizationSystem = null) | Iso3166Part2Subdivision | string? | Local variant of the native name, of the same name GetSubdivisionNativeName selects. |
GetSubdivisionParentCode() | Iso3166Part2Subdivision | string? | The parent subdivision code, if any. |
IsIndependent() | Iso3166Part1Alpha2Country / Iso3166Part1Alpha3Country | bool | Whether the country or territory is independent. |
The iso639LanguageCode parameter takes an ISO 639-1 or ISO 639-2/T code, such as en or eng, and matches it without regard to the case of its letters (RFC 5646 §2.1.1), so EN and Eng give the same name as en. A bibliographic ISO 639-2/B code, such as fre or chi, isn’t matched, and a null code gives null.
Applies to
Targets netstandard1.0, netstandard2.0, and net10.0.