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
collectionIKeyItemCollection<T>The collection with the item.
itemTItem to rename.
newKeystringNew key for the item.
Type Parameters
TThe 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,itemornewKeyis null.- ArgumentException
Thrown when
collectiondoes not contain theitem.- ArgumentException
Thrown when
itemhas 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
collectionIKeyItemCollection<T>The collection with the item.
keystringThe key of the value to get.
valueTWhen 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
trueif the IKeyItemCollection<T> contains an element with the specified key; otherwisefalse.
Type Parameters
TThe type of the elements in the collection.
Exceptions
- ArgumentNullException
Thrown when
collectionis null orkeyis null, empty or whitespace.