Table of Contents

Class LanguageMap

Namespace
Xapi
Assembly
Xapi.Core.dll

An immutable xAPI language map: RFC 5646 language tags mapped to strings in that language.

public sealed class LanguageMap : IReadOnlyDictionary<string, string>, IReadOnlyCollection<KeyValuePair<string, string>>, IEnumerable<KeyValuePair<string, string>>, IEnumerable, IEquatable<LanguageMap>
Inheritance
LanguageMap
Implements
Inherited Members

Remarks

Keys are validated as well-formed RFC 5646 tags (IEEE 9274.1.1, 4.2.7 "Language Maps") and compared case-insensitively, because language tags are case-insensitive. The original key spelling and insertion order are kept for writing. Equality ignores order.

Constructors

LanguageMap(IEnumerable<KeyValuePair<string, string>>)

Creates a language map.

public LanguageMap(IEnumerable<KeyValuePair<string, string>> entries)

Parameters

entries IEnumerable<KeyValuePair<string, string>>

The entries.

Exceptions

ArgumentException

A key is not a well-formed language tag, a value is null, or two keys differ only in case.

Properties

Count

Gets the number of elements in the collection.

public int Count { get; }

Property Value

int

The number of elements in the collection.

Empty

The empty language map.

public static LanguageMap Empty { get; }

Property Value

LanguageMap

this[string]

Gets the string for a language tag (case-insensitive).

public string this[string key] { get; }

Parameters

key string

The language tag.

Property Value

string

The string.

Exceptions

KeyNotFoundException

The tag is not in the map.

Keys

The language tags, in insertion order.

public IEnumerable<string> Keys { get; }

Property Value

IEnumerable<string>

Values

The strings, in insertion order.

public IEnumerable<string> Values { get; }

Property Value

IEnumerable<string>

Methods

ContainsKey(string)

Determines whether the read-only dictionary contains an element that has the specified key.

public bool ContainsKey(string key)

Parameters

key string

The key to locate.

Returns

bool

true if the read-only dictionary contains an element that has the specified key; otherwise, false.

Exceptions

ArgumentNullException

key is null.

Create(string, string)

Creates a map with a single entry.

public static LanguageMap Create(string languageTag, string value)

Parameters

languageTag string

An RFC 5646 language tag, for example en-US.

value string

The string.

Returns

LanguageMap

The map.

Equals(object?)

Determines whether the specified object is equal to the current object.

public override bool Equals(object? obj)

Parameters

obj object

The object to compare with the current object.

Returns

bool

true if the specified object is equal to the current object; otherwise, false.

Equals(LanguageMap?)

Indicates whether the current object is equal to another object of the same type.

public bool Equals(LanguageMap? other)

Parameters

other LanguageMap

An object to compare with this object.

Returns

bool

true if the current object is equal to the other parameter; otherwise, false.

GetEnumerator()

Returns an enumerator that iterates through the collection.

public IEnumerator<KeyValuePair<string, string>> GetEnumerator()

Returns

IEnumerator<KeyValuePair<string, string>>

An enumerator that can be used to iterate through the collection.

GetHashCode()

Serves as the default hash function.

public override int GetHashCode()

Returns

int

A hash code for the current object.

IsValidLanguageTag(string?)

Checks whether a string is a well-formed RFC 5646 language tag.

public static bool IsValidLanguageTag(string? languageTag)

Parameters

languageTag string

The candidate tag.

Returns

bool

true when the tag is well-formed.

ToString()

Returns the entries formatted as {en-US: text}.

public override string ToString()

Returns

string

A diagnostic string.

TryGetValue(string, out string)

Gets the value that is associated with the specified key.

public bool TryGetValue(string key, out string value)

Parameters

key string

The key to locate.

value string

When this method returns, the value associated with the specified key, if the key is found; otherwise, the default value for the type of the value parameter. This parameter is passed uninitialized.

Returns

bool

true if the object that implements the IReadOnlyDictionary<TKey, TValue> interface contains an element that has the specified key; otherwise, false.

Exceptions

ArgumentNullException

key is null.

With(string, string)

Returns a new map with the entry added, or replaced when the tag already exists.

public LanguageMap With(string languageTag, string value)

Parameters

languageTag string

An RFC 5646 language tag.

value string

The string.

Returns

LanguageMap

The new map.

Operators

operator ==(LanguageMap?, LanguageMap?)

Equality operator.

public static bool operator ==(LanguageMap? left, LanguageMap? right)

Parameters

left LanguageMap

The first map.

right LanguageMap

The second map.

Returns

bool

true when both maps hold the same entries.

operator !=(LanguageMap?, LanguageMap?)

Inequality operator.

public static bool operator !=(LanguageMap? left, LanguageMap? right)

Parameters

left LanguageMap

The first map.

right LanguageMap

The second map.

Returns

bool

true when the maps differ.