Bcp47KeyedSubtag Struct

Definition

Namespace: DataStandardizer.LanguageTag

A subtag introduced by a single-character key — used for extension subtags (singleton u, t, …) and the private-use subtag (singleton x). The constructor is internal; you obtain instances from a Bcp47LanguageTag’s ExtensionSubtags and PrivateUseSubtag members.

public readonly struct Bcp47KeyedSubtag : IEquatable<Bcp47KeyedSubtag>

Remarks

The Singleton and Subtags getters throw InvalidOperationException when the instance is uninitialised (default-constructed). On the netstandard1.1 and netstandard2.0 targets nullability is expressed through System.Diagnostics.CodeAnalysis attributes such as [MaybeNull] and [DisallowNull] rather than C# nullable reference types. A project gets null warnings from them only on C# 8 or later with nullable enabled.

Equality and hashing ignore case, because RFC 5646 section 2.1.1 makes subtags case-insensitive and Bcp47LanguageTag equality does the same, so u-co-phonebk equals U-CO-PHONEBK. ToString, Singleton and Subtags return the subtag as written.

Properties

Each getter throws InvalidOperationException if the instance is uninitialised.

Property Signature Notes
Singleton char? Singleton { get; } The leading single character, or null if empty.
Subtags IReadOnlyList<string> Subtags { get; } The remaining hyphen-separated parts. Each read splits the subtag again and returns a new list.

Methods

Implicit implementation

Method Returns Notes
Equals(Bcp47KeyedSubtag other) bool Case-insensitive comparison of the subtag string.
Equals(object obj) bool Override.
GetHashCode() int Override. Case-insensitive, consistent with Equals.
ToString() string Override. Returns the raw subtag string.

Operators

Operator Signature Notes
Explicit explicit operator Bcp47KeyedSubtag(string) Throws InvalidCastException if null.
Implicit implicit operator string?(Bcp47KeyedSubtag) Unwraps to the raw subtag string.
Equality operator ==, != (Bcp47KeyedSubtag, Bcp47KeyedSubtag) Case-insensitive comparison of the subtag string.

Applies to

Targets netstandard1.1, netstandard2.0, and net10.0. On the .NET Standard targets nullability is expressed through 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. The public surface is otherwise the same.

See also


This site uses Just the Docs, a documentation theme for Jekyll.