Class Extensions
- Namespace
- Xapi
- Assembly
- Xapi.Core.dll
An immutable xAPI extensions map: IRI keys mapped to arbitrary JSON values, as found in
result.extensions, context.extensions, Activity definitions and the About resource.
public sealed class Extensions : IReadOnlyDictionary<Iri, JsonElement>, IReadOnlyCollection<KeyValuePair<Iri, JsonElement>>, IEnumerable<KeyValuePair<Iri, JsonElement>>, IEnumerable, IEquatable<Extensions>
- Inheritance
-
Extensions
- Implements
- Inherited Members
Remarks
Values are kept as JsonElement clones, so they are written back exactly as read (numbers keep their original text). Equality compares values deeply: object property order is ignored, arrays are ordered, numbers compare by value. Values are never validated (IEEE 9274.1.1, 4.2.7 "Extensions").
Constructors
Extensions(IEnumerable<KeyValuePair<Iri, JsonElement>>)
Creates an extensions map. Each value is cloned so it does not depend on its source document.
public Extensions(IEnumerable<KeyValuePair<Iri, JsonElement>> entries)
Parameters
entriesIEnumerable<KeyValuePair<Iri, JsonElement>>The entries.
Exceptions
- ArgumentException
A key is the default IRI or appears more than once, or a value is the default JsonElement.
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 extensions map.
public static Extensions Empty { get; }
Property Value
this[Iri]
Gets the value for a key.
public JsonElement this[Iri key] { get; }
Parameters
keyIriThe extension IRI.
Property Value
- JsonElement
The JSON value.
Exceptions
- KeyNotFoundException
The key is not in the map.
Keys
The keys, in insertion order.
public IEnumerable<Iri> Keys { get; }
Property Value
Values
The values, in insertion order.
public IEnumerable<JsonElement> Values { get; }
Property Value
Methods
ContainsKey(Iri)
Determines whether the read-only dictionary contains an element that has the specified key.
public bool ContainsKey(Iri key)
Parameters
keyIriThe 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(Iri, JsonElement)
Creates a map with a single entry.
public static Extensions Create(Iri key, JsonElement value)
Parameters
keyIriThe extension IRI.
valueJsonElementThe JSON value.
Returns
- Extensions
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(Extensions?)
Indicates whether the current object is equal to another object of the same type.
public bool Equals(Extensions? other)
Parameters
otherExtensionsAn object to compare with this object.
Returns
GetEnumerator()
Returns an enumerator that iterates through the collection.
public IEnumerator<KeyValuePair<Iri, JsonElement>> GetEnumerator()
Returns
- IEnumerator<KeyValuePair<Iri, JsonElement>>
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.
ToString()
Returns the keys formatted as {iri, iri}.
public override string ToString()
Returns
- string
A diagnostic string.
TryGetValue(Iri, out JsonElement)
Gets the value that is associated with the specified key.
public bool TryGetValue(Iri key, out JsonElement value)
Parameters
keyIriThe key to locate.
valueJsonElementWhen 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(Iri, JsonElement)
Returns a new map with the entry added, or replaced when the key already exists.
public Extensions With(Iri key, JsonElement value)
Parameters
keyIriThe extension IRI.
valueJsonElementThe JSON value.
Returns
- Extensions
The new map.
Operators
operator ==(Extensions?, Extensions?)
Equality operator.
public static bool operator ==(Extensions? left, Extensions? right)
Parameters
leftExtensionsThe first map.
rightExtensionsThe second map.
Returns
operator !=(Extensions?, Extensions?)
Inequality operator.
public static bool operator !=(Extensions? left, Extensions? right)
Parameters
leftExtensionsThe first map.
rightExtensionsThe second map.