Class SequentialDictionary<TKey, TValue>
- Namespace
- LfrlAnvil.Collections
- Assembly
- LfrlAnvil.Collections.dll
Represents a generic collection of (key, value) pairs whose insertion order is preserved.
public class SequentialDictionary<TKey, TValue> : IDictionary<TKey, TValue>, ICollection<KeyValuePair<TKey, TValue>>, IReadOnlyDictionary<TKey, TValue>, IReadOnlyCollection<KeyValuePair<TKey, TValue>>, IEnumerable<KeyValuePair<TKey, TValue>>, IEnumerable where TKey : notnull
Type Parameters
TKey
Key type.
TValue
Value type.
- Inheritance
-
SequentialDictionary<TKey, TValue>
- Implements
-
IDictionary<TKey, TValue>ICollection<KeyValuePair<TKey, TValue>>IReadOnlyDictionary<TKey, TValue>IReadOnlyCollection<KeyValuePair<TKey, TValue>>IEnumerable<KeyValuePair<TKey, TValue>>
- Inherited Members
- Extension Methods
Constructors
SequentialDictionary()
Creates a new empty SequentialDictionary<TKey, TValue> instance with Default comparer.
public SequentialDictionary()
SequentialDictionary(IEqualityComparer<TKey>)
Creates a new empty SequentialDictionary<TKey, TValue> instance.
public SequentialDictionary(IEqualityComparer<TKey> comparer)
Parameters
comparer
IEqualityComparer<TKey>Key equality comparer.
Properties
Comparer
Key equality comparer.
public IEqualityComparer<TKey> Comparer { get; }
Property Value
- IEqualityComparer<TKey>
Count
Gets the number of elements contained in the ICollection<T>.
public int Count { get; }
Property Value
- int
The number of elements contained in the ICollection<T>.
First
First entry in order of insertion.
public KeyValuePair<TKey, TValue>? First { get; }
Property Value
- KeyValuePair<TKey, TValue>?
this[TKey]
Gets or sets the element with the specified key.
public TValue this[TKey key] { get; set; }
Parameters
key
TKeyThe key of the element to get or set.
Property Value
- TValue
The element with the specified key.
Exceptions
- ArgumentNullException
key
is null.- KeyNotFoundException
The property is retrieved and
key
is not found.- NotSupportedException
The property is set and the IDictionary<TKey, TValue> is read-only.
Keys
Gets an enumerable collection that contains the keys in the read-only dictionary.
public IEnumerable<TKey> Keys { get; }
Property Value
- IEnumerable<TKey>
An enumerable collection that contains the keys in the read-only dictionary.
Last
Last entry in order of insertion.
public KeyValuePair<TKey, TValue>? Last { get; }
Property Value
- KeyValuePair<TKey, TValue>?
Values
Gets an enumerable collection that contains the values in the read-only dictionary.
public IEnumerable<TValue> Values { get; }
Property Value
- IEnumerable<TValue>
An enumerable collection that contains the values in the read-only dictionary.
Methods
Add(TKey, TValue)
Adds an element with the provided key and value to the IDictionary<TKey, TValue>.
public void Add(TKey key, TValue value)
Parameters
key
TKeyThe object to use as the key of the element to add.
value
TValueThe object to use as the value of the element to add.
Exceptions
- ArgumentNullException
key
is null.- ArgumentException
An element with the same key already exists in the IDictionary<TKey, TValue>.
- NotSupportedException
The IDictionary<TKey, TValue> is read-only.
Clear()
Removes all items from the ICollection<T>.
public void Clear()
Exceptions
- NotSupportedException
The ICollection<T> is read-only.
ContainsKey(TKey)
Determines whether the IDictionary<TKey, TValue> contains an element with the specified key.
[Pure]
public bool ContainsKey(TKey key)
Parameters
key
TKeyThe key to locate in the IDictionary<TKey, TValue>.
Returns
- bool
true if the IDictionary<TKey, TValue> contains an element with the key; otherwise, false.
Exceptions
- ArgumentNullException
key
is null.
GetEnumerator()
Creates a new LinkedListSlimNodeEnumerator<T> instance for this dictionary.
[Pure]
public LinkedListSlimNodeEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
Returns
- LinkedListSlimNodeEnumerator<KeyValuePair<TKey, TValue>>
New LinkedListSlimNodeEnumerator<T> instance.
Remove(TKey)
Removes the element with the specified key from the IDictionary<TKey, TValue>.
public bool Remove(TKey key)
Parameters
key
TKeyThe key of the element to remove.
Returns
- bool
true if the element is successfully removed; otherwise, false. This method also returns false if
key
was not found in the original IDictionary<TKey, TValue>.
Exceptions
- ArgumentNullException
key
is null.- NotSupportedException
The IDictionary<TKey, TValue> is read-only.
Remove(TKey, out TValue)
Attempts to remove an entry associated with the specified key
.
public bool Remove(TKey key, out TValue removed)
Parameters
key
TKeyKey to remove.
removed
TValueout parameter that returns removed value associated with the specified
key
.
Returns
- bool
true when entry was removed, otherwise false.
TryGetValue(TKey, out TValue)
Gets the value associated with the specified key.
public bool TryGetValue(TKey key, out TValue result)
Parameters
key
TKeyThe key whose value to get.
result
TValue
Returns
- bool
true if the object that implements IDictionary<TKey, TValue> contains an element with the specified key; otherwise, false.
Exceptions
- ArgumentNullException
key
is null.