Class BaseKeyedCollection<TItem>

A base class for collections of items with Name and ID properties.

System.Object
  Stonefield.Collections.BaseKeyedCollection<TItem>
public abstract class BaseKeyedCollection<TItem> : object, ICollection<TItem>,
   IEnumerable<TItem>,
   IEnumerable

Remarks

The class has a few use cases: (1) If the item class has dependencies that we want the collection rather than the developer to set up for us. That's why InsertItem and SetItem call SetItemProperties, which should be overridden in a subclass to set up the dependencies. (2) The key for the collection is ID. (3) If the indexer should work on either name or ID, and be case-insensitive on name. (4) If the indexer should return null rather than throwing an error if the item isn't found.

Class Members

MemberDescription

CollectionChanged

Raised when the collection is changed.

Add

Adds an item to the collection.

public virtual void Add(TItem item);

Clear

Clears the collection.

public virtual void Clear();

Contains

Returns true if the collection contains the specified item.

public sealed bool Contains(TItem item);

CopyTo

Copies the collection to the specified array starting from the specified index.

public virtual void CopyTo(TItem[] array,
    int arrayIndex);

public virtual void CopyTo(TItem[] array,
    int arrayIndex)

GetEnumerator

Returns an enumerator that iterates through the collection.

public virtual IEnumerator<TItem> GetEnumerator();

GetItem

Returns the item with the specified name or ID.

public sealed TItem GetItem(string name);

public sealed TItem GetItem(int index);

GetItems

Returns an array with all items in the collection.

public TItem[] GetItems();

New

Creates an item and adds it to the collection.

public virtual TItem New(string name);

public virtual TItem New();

Remove

Removes an item from the collection.

public virtual bool Remove(TItem item);

ToString

Display the collection count

public virtual string ToString();

Count

The number of items in the collection.

IsReadOnly

Indicates whether the collection is read-only.

Item

Requirements

Namespace: Stonefield.Collections
Assembly: collections.dll