Table of Contents

Class KeyItemCollectionExtension

Namespace
Loehnert.Utility.Extensions
Assembly
Loehnert.Utility.dll

Extensions for objects of type IKeyItemCollection<T>.

public static class KeyItemCollectionExtension
Inheritance
KeyItemCollectionExtension
Inherited Members

Methods

RenameItem<T>(IKeyItemCollection<T>, T, string)

Renames an item in the collection. This means removing the item, changing the key and inserting it in the previous position. Therefor item must have a public setter for the Key property.

public static void RenameItem<T>(this IKeyItemCollection<T> collection, T item, string newKey) where T : IHasKey

Parameters

collection IKeyItemCollection<T>

The collection with the item.

item T

Item to rename.

newKey string

New key for the item.

Type Parameters

T

The type of the elements in the collection.

Remarks

The KeyItemCollection<T> does not update the inner dictionary while changing the key of a item.

Exceptions

ArgumentNullException

Thrown when collection, item or newKey is null.

ArgumentException

Thrown when collection does not contain the item.

ArgumentException

Thrown whenitem has no public setter for Key.

TryGetValue<T>(IKeyItemCollection<T>, string, out T)

Gets the value associated with the specified key.

public static bool TryGetValue<T>(this IKeyItemCollection<T> collection, string key, out T value) where T : IHasKey

Parameters

collection IKeyItemCollection<T>

The collection with the item.

key string

The key of the value to get.

value T

When this method returns, contains 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 IKeyItemCollection<T> contains an element with the specified key; otherwise false.

Type Parameters

T

The type of the elements in the collection.

Exceptions

ArgumentNullException

Thrown when collection is null or key is null, empty or whitespace.