Table of Contents

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

entries IEnumerable<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

Extensions

this[Iri]

Gets the value for a key.

public JsonElement this[Iri key] { get; }

Parameters

key Iri

The 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

IEnumerable<Iri>

Values

The values, in insertion order.

public IEnumerable<JsonElement> Values { get; }

Property Value

IEnumerable<JsonElement>

Methods

ContainsKey(Iri)

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

public bool ContainsKey(Iri key)

Parameters

key Iri

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(Iri, JsonElement)

Creates a map with a single entry.

public static Extensions Create(Iri key, JsonElement value)

Parameters

key Iri

The extension IRI.

value JsonElement

The 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

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(Extensions?)

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

public bool Equals(Extensions? other)

Parameters

other Extensions

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<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

key Iri

The key to locate.

value JsonElement

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(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

key Iri

The extension IRI.

value JsonElement

The JSON value.

Returns

Extensions

The new map.

Operators

operator ==(Extensions?, Extensions?)

Equality operator.

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

Parameters

left Extensions

The first map.

right Extensions

The second map.

Returns

bool

true when both maps hold deeply equal entries.

operator !=(Extensions?, Extensions?)

Inequality operator.

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

Parameters

left Extensions

The first map.

right Extensions

The second map.

Returns

bool

true when the maps differ.