Show / Hide Table of Contents

Class NamedCollection<T>

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

Inheritance
Object
NamedCollection<T>
Implements
ICloneable<NamedCollection<T>>
Namespace: NanoByte.Common.Collections
Assembly: NanoByte.Common.dll
Syntax
public class NamedCollection<T> : KeyedCollection<string, T>, ICloneable<NamedCollection<T>> where T : INamed
Type Parameters
Name Description
T
Remarks

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

Constructors

NamedCollection()

Creates a new named collection.

Declaration
public NamedCollection()

NamedCollection(IEnumerable<T>)

Creates a new named collection pre-filled with elements.

Declaration
public NamedCollection(IEnumerable<T> elements)
Parameters
Type Name Description
IEnumerable<T> elements

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

Methods

ClearItems()

Declaration
protected override void ClearItems()

Clone()

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

Declaration
public virtual NamedCollection<T> Clone()
Returns
Type Description
NamedCollection<T>

The cloned collection.

GetKeyForItem(T)

Declaration
protected override string GetKeyForItem(T item)
Parameters
Type Name Description
T item
Returns
Type Description
String

InsertItem(Int32, T)

Declaration
protected override void InsertItem(int index, T item)
Parameters
Type Name Description
Int32 index
T item

RemoveItem(Int32)

Declaration
protected override void RemoveItem(int index)
Parameters
Type Name Description
Int32 index

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!

Declaration
public void Rename(T element, string newName)
Parameters
Type Name Description
T element

The element to rename.

String newName

The new Name for the element.

Exceptions
Type Condition
KeyNotFoundException

The element is not in the collection.

InvalidOperationException

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

SetItem(Int32, T)

Declaration
protected override void SetItem(int index, T item)
Parameters
Type Name Description
Int32 index
T item

Events

CollectionChanged

Declaration
public event Action<object> CollectionChanged
Event Type
Type Description
Action<Object>

Implements

ICloneable<T>

Extension Methods

UpdateUtils.To<TIn, TOut>(TIn, Func<TIn, TOut>)
JsonStorage.SaveJson<T>(T, Stream)
JsonStorage.SaveJson<T>(T, String)
JsonStorage.ToJsonString<T>(T)
JsonStorage.ReparseAsJson<T>(Object)
JsonStorage.ReparseAsJson<T>(Object, T)
XmlStorage.SaveXml(Object, Stream, String)
XmlStorage.SaveXml<T>(T, String, String)
XmlStorage.ToXmlString(Object, String)
ConversionUtils.ConvertToString<TType>(TType)
In This Article
Back to top Copyright Bastian Eicher