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
TItem to rename.
newKey
stringNew 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
ornewKey
is null.- ArgumentException
Thrown when
collection
does not contain theitem
.- ArgumentException
Thrown when
item
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
stringThe key of the value to get.
value
TWhen 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; otherwisefalse
.
Type Parameters
T
The type of the elements in the collection.
Exceptions
- ArgumentNullException
Thrown when
collection
is null orkey
is null, empty or whitespace.