Table of Contents

Class SelfCheckingDictionary<K, V>

Namespace
Nautilus.Utility
Assembly
Nautilus.dll
This dictionary structure automatically checks for duplicate keys as they are being added to the collection. Duplicate entries are logged and removed from the final collection.
public class SelfCheckingDictionary<K, V> : IDictionary<K, V>, ICollection<KeyValuePair<K, V>>, IEnumerable<KeyValuePair<K, V>>, IEnumerable

Type Parameters

K
The Key Type
V
The Value Type
Inheritance
SelfCheckingDictionary<K, V>
Implements
Inherited Members
Extension Methods

Constructors

SelfCheckingDictionary(string, IEqualityComparer<K>, Func<K, string>)

Creates a SelfCheckingDictionary<K, V> with an EqualityComparer and an optional ToString function.
public SelfCheckingDictionary(string collectionName, IEqualityComparer<K> equalityComparer, Func<K, string> toLog = null)

Parameters

collectionName string
equalityComparer IEqualityComparer<K>
toLog Func<K, string>

SelfCheckingDictionary(string, Func<K, string>)

Creates a SelfCheckingDictionary<K, V> with an optional ToString function.
public SelfCheckingDictionary(string collectionName, Func<K, string> toLog = null)

Parameters

collectionName string
toLog Func<K, string>

Properties

Count

Gets the number of unique entries in the SelfCheckingDictionary<K, V>
public int Count { get; }

Property Value

int

IsReadOnly

Defaults to false.
public bool IsReadOnly { get; }

Property Value

bool

this[K]

Gets a key value pair from the collection or sets a key value pair into the collection. When setting, if a key already exists, the previous entry will be discarded.
public V this[K key] { get; set; }

Parameters

key K
The unique key.

Property Value

V
The value corresponding to the key.

Keys

Gets a collection containing the keys in the SelfCheckingDictionary<K, V>
public ICollection<K> Keys { get; }

Property Value

ICollection<K>

Values

Gets a collection containing the values in the SelfCheckingDictionary<K, V>
public ICollection<V> Values { get; }

Property Value

ICollection<V>

Methods

Add(KeyValuePair<K, V>)

Add a new entry the collection. If a duplicate key is found, the new value will be discarded.
public void Add(KeyValuePair<K, V> item)

Parameters

item KeyValuePair<K, V>
The key value pair.

Add(K, V)

Add a new entry the collection. If a duplicate key is found, the new value will be discarded.
public void Add(K key, V value)

Parameters

key K
The unique key.
value V
The value.

Clear()

public void Clear()

Contains(KeyValuePair<K, V>)

public bool Contains(KeyValuePair<K, V> item)

Parameters

item KeyValuePair<K, V>

Returns

bool

ContainsKey(K)

public bool ContainsKey(K key)

Parameters

key K

Returns

bool

CopyTo(KeyValuePair<K, V>[], int)

public void CopyTo(KeyValuePair<K, V>[] array, int arrayIndex)

Parameters

array KeyValuePair<K, V>[]
arrayIndex int

GetEnumerator()

public IEnumerator<KeyValuePair<K, V>> GetEnumerator()

Returns

IEnumerator<KeyValuePair<K, V>>

Remove(KeyValuePair<K, V>)

public bool Remove(KeyValuePair<K, V> item)

Parameters

item KeyValuePair<K, V>

Returns

bool

Remove(K)

public bool Remove(K key)

Parameters

key K

Returns

bool

TryGetValue(K, out V)

public bool TryGetValue(K key, out V value)

Parameters

key K
value V

Returns

bool