Table of Contents

Class NamedCollection<T>

Namespace
NanoByte.Common.Collections
Assembly
NanoByte.Common.dll

A keyed collection (pseudo-dictionary) of INamed objects. Case-insensitive!

public class NamedCollection<T> : KeyedCollection<string, T>, ICloneable<NamedCollection<T>> where T : INamed

Type Parameters

T
Inheritance
object
Collection<T>
KeyedCollection<string, T>
NamedCollection<T>
Implements
Extension Methods

Remarks

Elements are automatically maintained in an alphabetically sorted order. Suitable for XML serialization.

Constructors

NamedCollection()

A keyed collection (pseudo-dictionary) of INamed objects. Case-insensitive!

public NamedCollection()

Remarks

Elements are automatically maintained in an alphabetically sorted order. Suitable for XML serialization.

NamedCollection(IEnumerable<T>)

Creates a new named collection pre-filled with elements.

public NamedCollection(IEnumerable<T> elements)

Parameters

elements IEnumerable<T>

The elements to pre-fill the collection with. Must all have unique Names!

Methods

ClearItems()

Removes all elements from the System.Collections.ObjectModel.KeyedCollection<TKey, TItem>.

protected override void ClearItems()

Clone()

Creates a shallow copy of this collection (elements are not cloned).

public virtual NamedCollection<T> Clone()

Returns

NamedCollection<T>

The cloned collection.

GetKeyForItem(T)

When implemented in a derived class, extracts the key from the specified element.

protected override string GetKeyForItem(T item)

Parameters

item T

The element from which to extract the key.

Returns

string

The key for the specified element.

InsertItem(int, T)

Inserts an element into the System.Collections.ObjectModel.KeyedCollection<TKey, TItem> at the specified index.

protected override void InsertItem(int index, T item)

Parameters

index int

The zero-based index at which item should be inserted.

item T

The object to insert.

Exceptions

ArgumentOutOfRangeException

index is less than 0.-or-index is greater than System.Collections.ObjectModel.Collection<T>.Count.

RemoveItem(int)

Removes the element at the specified index of the System.Collections.ObjectModel.KeyedCollection<TKey, TItem>.

protected override void RemoveItem(int index)

Parameters

index int

The index of the element to remove.

Rename(T, string)

Renames an element in the list. Renaming an element in the list directly (without using this method) will prevent lookups from working properly!

[CollectionAccess(CollectionAccessType.ModifyExistingContent)]
public void Rename(T element, string newName)

Parameters

element T

The element to rename.

newName string

The new Name for the element.

Exceptions

KeyNotFoundException

The element is not in the collection.

InvalidOperationException

The newName is already taken by another element in the collection.

SetItem(int, T)

Replaces the item at the specified index with the specified item.

protected override void SetItem(int index, T item)

Parameters

index int

The zero-based index of the item to be replaced.

item T

The new item.

Events

CollectionChanged

public event Action<object>? CollectionChanged

Event Type

Action<object>