Table of Contents

Class OrderedDictionary<TKey, TValue>

Namespace
Vintagestory.API.Datastructures
Assembly
VintagestoryAPI.dll

Same as your normal C# Dictionary but ensures that the order in which the items are added is remembered. That way you can iterate over the dictionary with the insert order intact or set/get elements by index. Taken from http://www.codeproject.com/Articles/18615/OrderedDictionary-T-A-generic-implementation-of-IO Please be aware that this is not a very efficient implementation, recommed use only for small sets of data.

[ProtoContract]
public class OrderedDictionary<TKey, TValue> : IDictionary<TKey, TValue>, ICollection<KeyValuePair<TKey, TValue>>, IEnumerable<KeyValuePair<TKey, TValue>>, IEnumerable

Type Parameters

TKey
TValue
Inheritance
OrderedDictionary<TKey, TValue>
Implements
IDictionary<TKey, TValue>
ICollection<KeyValuePair<TKey, TValue>>
IEnumerable<KeyValuePair<TKey, TValue>>
Inherited Members
Extension Methods

Constructors

OrderedDictionary()

public OrderedDictionary()

OrderedDictionary(Dictionary<TKey, TValue>)

public OrderedDictionary(Dictionary<TKey, TValue> initialData)

Parameters

initialData Dictionary<TKey, TValue>

OrderedDictionary(IEqualityComparer<TKey>)

public OrderedDictionary(IEqualityComparer<TKey> comparer)

Parameters

comparer IEqualityComparer<TKey>

OrderedDictionary(int)

public OrderedDictionary(int capacity)

Parameters

capacity int

OrderedDictionary(int, IEqualityComparer<TKey>)

public OrderedDictionary(int capacity, IEqualityComparer<TKey> comparer)

Parameters

capacity int
comparer IEqualityComparer<TKey>

OrderedDictionary(OrderedDictionary<TKey, TValue>)

public OrderedDictionary(OrderedDictionary<TKey, TValue> initialData)

Parameters

initialData OrderedDictionary<TKey, TValue>

Properties

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

InternalDictionary

public Dictionary<TKey, TValue> InternalDictionary { get; }

Property Value

Dictionary<TKey, TValue>

IsReadOnly

Gets a value indicating whether the ICollection<T> is read-only.

public bool IsReadOnly { get; }

Property Value

bool

true if the ICollection<T> is read-only; otherwise, false.

this[TKey]

Gets or sets the element with the specified key.

public TValue this[TKey key] { get; set; }

Parameters

key TKey

The 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 ICollection<T> containing the keys of the IDictionary<TKey, TValue>.

public ICollection<TKey> Keys { get; }

Property Value

ICollection<TKey>

An ICollection<T> containing the keys of the object that implements IDictionary<TKey, TValue>.

Values

Important: these are NOT ordered. The ordered values is obtained by .ValuesOrdered

public ICollection<TValue> Values { get; }

Property Value

ICollection<TValue>

ValuesOrdered

public IEnumerable<TValue> ValuesOrdered { get; }

Property Value

IEnumerable<TValue>

Methods

Add(TKey, TValue)

public int Add(TKey key, TValue value)

Parameters

key TKey
value TValue

Returns

int

BeforeSerialization()

[ProtoBeforeSerialization]
protected void BeforeSerialization()

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.

public bool ContainsKey(TKey key)

Parameters

key TKey

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

ContainsValue(TValue)

public bool ContainsValue(TValue value)

Parameters

value TValue

Returns

bool

GetEnumerator()

public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()

Returns

IEnumerator<KeyValuePair<TKey, TValue>>

GetKeyAtIndex(int)

public TKey GetKeyAtIndex(int index)

Parameters

index int

Returns

TKey

GetValueAtIndex(int)

public TValue GetValueAtIndex(int index)

Parameters

index int

Returns

TValue

IndexOfKey(TKey)

Returns -1 if the key was not found

public int IndexOfKey(TKey key)

Parameters

key TKey

Returns

int

Insert(int, TKey, TValue)

public void Insert(int index, TKey key, TValue value)

Parameters

index int
key TKey
value TValue

InsertBefore(TKey, TKey, TValue)

public void InsertBefore(TKey Atkey, TKey key, TValue value)

Parameters

Atkey TKey
key TKey
value TValue

OnDeserializedMethod(StreamingContext)

[OnDeserialized]
protected void OnDeserializedMethod(StreamingContext context)

Parameters

context StreamingContext

Remove(TKey)

Removes the element with the specified key from the IDictionary<TKey, TValue>.

public bool Remove(TKey key)

Parameters

key TKey

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

RemoveAt(int)

public void RemoveAt(int index)

Parameters

index int

SetAtIndex(int, TValue)

public void SetAtIndex(int index, TValue value)

Parameters

index int
value TValue

TryGetValue(TKey)

public TValue TryGetValue(TKey key)

Parameters

key TKey

Returns

TValue

TryGetValue(TKey, out TValue)

Gets the value associated with the specified key.

public bool TryGetValue(TKey key, out TValue value)

Parameters

key TKey

The key whose value to get.

value TValue

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 IDictionary<TKey, TValue> contains an element with the specified key; otherwise, false.

Exceptions

ArgumentNullException

key is null.