Table of Contents

Class Collection<T>

Namespace
PolarStudioGlobals
Assembly
PolarStudioGlobals.dll

The collection is an ordered list with items that may (or may not) have a key as index.

public class Collection<T> : IEnumerable

Type Parameters

T
Inheritance
Collection<T>
Implements
Derived
Inherited Members
Extension Methods

Constructors

Collection(bool, CompareMode)

Constructor for a new collection.

public Collection(bool pZeroBased = false, CompareMode pCompareMode = CompareMode.Text)

Parameters

pZeroBased bool

If True, the index of the collection starts at 0, else it starts at 1.

pCompareMode CompareMode

The CompareMode to use

Properties

CompareMode

Gets/sets the CompareMode. A binary compare mode (0) means the keys are compared case-sensitive (both 'aa' and 'AA' may exist). A text compare mode (1) means the keys are case-insensitive.

public CompareMode CompareMode { get; set; }

Property Value

CompareMode

Count

Returns the number of elements in this collection.

public int Count { get; }

Property Value

int

this[object]

This default property returns an element either by index (int) or key (string)

public T this[object Index] { get; }

Parameters

Index object

The index or key for the element to get.

Property Value

T

The found element.

Exceptions

Exception

Raises an exeception if index out of bounds or key not found.

ZeroBased

Gets/sets if the collection is zero-based (meaning the first element is at location 0).

public bool ZeroBased { get; set; }

Property Value

bool

Methods

Add(T, string, object, object)

Adds an element to the collection.

public Collection<T> Add(T Item, string Key = "", object Before = null, object After = null)

Parameters

Item T

The element to add.

Key string

The key used for this element (optional).

Before object

The element before which this new element is added (either index or key).

After object

The element after which this new element is added (either index or key).

Returns

Collection<T>

This collection.

Exceptions

Exception

Clear()

Erases the whole collection.

public void Clear()

ContainsKey(string)

Returns True if the collection contains the specified key.

public bool ContainsKey(string pKey)

Parameters

pKey string

The key to search for.

Returns

bool

True if the key is found.

Elements()

Returns the elements as an array. Can be used as a temporary clone in situations where collections may change while looping over the collections.

public T[] Elements()

Returns

T[]

First()

Returns the first element in the collection.

public T First()

Returns

T

GetEnumerator()

The enumerator.

public IEnumerator GetEnumerator()

Returns

IEnumerator

GetJSON()

Returns the JSON for this collection (as array).

public string GetJSON()

Returns

string

Keys()

Returns the keys in the collection as array of strings.

public string[] Keys()

Returns

string[]

Last()

Returns the last element in the collection.

public T Last()

Returns

T

Prepend(T, string)

Adds an element as the first element in the collection.

public Collection<T> Prepend(T Item, string Key = "")

Parameters

Item T

The element to add.

Key string

The key used for this element (optional).

Returns

Collection<T>

This collection.

Exceptions

Exception

Remove(object)

Removes an element by index (int) or key (string). Throws an error if index out of bounds or key not found.

public Collection<T> Remove(object Index)

Parameters

Index object

The index or key of the element to remove.

Returns

Collection<T>

This collection.

TryGet(object, T)

Tries to get an element either by index (int) or key (string). Returns the specified DefaultValue if not found.

public T TryGet(object Index, T DefaultValue = default)

Parameters

Index object

The index or key for the element to get.

DefaultValue T

The value to use in case the element is not found.

Returns

T

The found element or else the DefaultValue

TryRemove(object)

Removes an element by index (int) or key (string). No action if index out of bounds or key not found.

public Collection<T> TryRemove(object Index)

Parameters

Index object

The index or key of the element to remove.

Returns

Collection<T>

This collection.

UpdateKey(object, string)

Updates a key for an element in the collection.

public void UpdateKey(object Index, string pNewKey)

Parameters

Index object

The index or key for the element to get.

pNewKey string

The new key to use. May be empty.

Exceptions

Exception

Throws an error if the key is not unique.