IdList<T>

public sealed class IdList<T>
A fast dictionary for objects with GUID keys. This type differs from Dictionary(Guid, T) by sacrificing memory for lookup performance. Adding entries may be slower and require more allocations, however finding entries ought to be slightly faster. This collection is not thread-safe and any modifying calls must be made from within a lock statement.
T

Constructors

IdList

#
public IdList(Func<T, Guid> keyGenerator)
Create a new, empty collection.
keyGenerator (Func<T, Guid>)

Properties

Count

#
public int Count { get; }
Gets the number of objects stored in this collection.

Values

#
public IEnumerable<T> Values { get; }
Enumerate over all instances of T stored in this collection

Methods

Add

#
public void Add(T instance)
Add a new instance to this collection. If another instance with the same ID is already part of this collection, nothing will happen.
instance (T)Instance to add.

Clear

#
public void Clear()
Clear all values.

Contains

#
public bool Contains(Guid id)
Test whether a given key exists within this collection.
id (Guid)

Contains

#
public bool Contains(T instance)
Test whether an instance with the same GUID as the argument exists within this collection.
instance (T)

Find

#
public bool Find(Guid id, out T instance)
Retrieve the instance which matches the ID.
id (Guid)ID key to search for.
instance (out T)Instance associated with id, if any.
True if an instance was found.

Remove

#
public bool Remove(Guid id)
Remove the instance which is associated with the given ID.
id (Guid)

Remove

#
public bool Remove(T instance)
Remove the instance with an ID which matches the supplied instance.
instance (T)

Set

#
public void Set(T instance)
Add a new instance to this collection. Any existing instance with a matching key will be overwritten.
instance (T)Instance to add.

ToArray

#
public T[] ToArray()
Convert this list into an array.

Update

#
public bool Update(Guid oldId)
Update a value at an old ID. This may be necessary if a value stored inside this collection has mutated and now resolves to a different ID.
oldId (Guid)Old id to look at.