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
entriesIEnumerable<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
this[string]
Gets the string for a language tag (case-insensitive).
public string this[string key] { get; }
Parameters
keystringThe 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
Values
The strings, in insertion order.
public IEnumerable<string> Values { get; }
Property Value
Methods
ContainsKey(string)
Determines whether the read-only dictionary contains an element that has the specified key.
public bool ContainsKey(string key)
Parameters
keystringThe key to locate.
Returns
- bool
true if the read-only dictionary contains an element that has the specified key; otherwise, false.
Exceptions
- ArgumentNullException
keyis null.
Create(string, string)
Creates a map with a single entry.
public static LanguageMap Create(string languageTag, string value)
Parameters
Returns
- LanguageMap
The map.
Equals(object?)
Determines whether the specified object is equal to the current object.
public override bool Equals(object? obj)
Parameters
objobjectThe object to compare with the current object.
Returns
Equals(LanguageMap?)
Indicates whether the current object is equal to another object of the same type.
public bool Equals(LanguageMap? other)
Parameters
otherLanguageMapAn object to compare with this object.
Returns
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
languageTagstringThe candidate tag.
Returns
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
keystringThe key to locate.
valuestringWhen this method returns, the value associated with the specified key, if the key is found; otherwise, the default value for the type of the
valueparameter. 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
keyis 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
Returns
- LanguageMap
The new map.
Operators
operator ==(LanguageMap?, LanguageMap?)
Equality operator.
public static bool operator ==(LanguageMap? left, LanguageMap? right)
Parameters
leftLanguageMapThe first map.
rightLanguageMapThe second map.
Returns
operator !=(LanguageMap?, LanguageMap?)
Inequality operator.
public static bool operator !=(LanguageMap? left, LanguageMap? right)
Parameters
leftLanguageMapThe first map.
rightLanguageMapThe second map.