Key.

Key.KeyedList<T> Class

Summary

A System.Collections.Generic.List`1 which can remove items without needing to search through the entire collection. Does not allow nulls to be added.
Assembly
Animancer.dll
Namespace
Animancer
Interfaces
  • IList<T>
  • ICollection
Base Types
  • Object
graph BT Type-->Base0["Object"] Type-.->Interface0["IList<T>"] Type-.->Interface1["ICollection"] Type["Key.KeyedList<T>"] class Type type-node

Syntax

public sealed class Key.KeyedList<T> : IList<T>, ICollection where T : class, IKeyHolder

Examples

To use an object in a Keyed List, it must either inherit from Animancer.Key or implement Animancer.IKeyHolder like so:
class MyClass : IKeyHolder
{
    private readonly Key Key = new Key();
    Key IKeyHolder.Key => Key;
}
Note that the Key field can be made public if desired.

Remarks

This class is nested inside Animancer.Key so it can modify the private Animancer.Key._Index without exposing that capability to anything else.

Type Parameters

Name Description
T

Constructors

Name Summary
KeyedList() Creates a new Animancer.Key.KeyedList`1 using the default System.Collections.Generic.List`1 constructor.
KeyedList(int) Creates a new Animancer.Key.KeyedList`1 with the specified initial `capacity`.

Properties

Name Value Summary
Capacity int
The number of items that this list can contain before resizing is required.
Count int
The number of items currently in the list.
this[int] T
Gets or sets the item at the specified `index`.

Methods

Name Value Summary
Add(T) void
Adds the `item` to the end of this list.
AddNew(T) void
Adds the `item` to the end of this list if it wasn't already in it.
Clear() void
Removes all items from this list.
Contains(T) bool
Indicates whether the `item` is currently in this list.
CopyTo(T[], int) void
Copies all the items from this list into the `array`, starting at the specified `index`.
GetEnumerator() IEnumerator<T>
Returns an enumerator that iterates through this list.
IndexOf(T) int
Returns the index of the `item` in this list or -1 if it is not in this list.
Insert(int, T) void
Adds the `item` to this list at the specified `index`.
Remove(T) bool
Removes the `item` from this list.
RemoveAt(int) void
Removes the item at the specified `index`.
RemoveAtSwap(int) void
Removes the item at the specified `index` by swapping the last item in this list into its place.

This does not maintain the order of items, but is more efficient than Animancer.Key.KeyedList`1.RemoveAt(System.Int32) because it avoids the need to move every item after the target down one place.
RemoveSwap(T) bool
Removes the `item` by swapping the last item in this list into its place.

This does not maintain the order of items, but is more efficient than Animancer.Key.KeyedList`1.Remove(`0) because it avoids the need to move every item after the target down one place.