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> : IEnumerableType 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
- pZeroBasedbool
- If True, the index of the collection starts at 0, else it starts at 1. 
- pCompareModeCompareMode
- 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
Count
Returns the number of elements in this collection.
public int Count { get; }Property Value
this[object]
This default property returns an element either by index (int) or key (string)
public T this[object Index] { get; }Parameters
- Indexobject
- 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
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
- ItemT
- The element to add. 
- Keystring
- The key used for this element (optional). 
- Beforeobject
- The element before which this new element is added (either index or key). 
- Afterobject
- The element after which this new element is added (either index or key). 
Returns
- Collection<T>
- This collection. 
Exceptions
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
- pKeystring
- 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
GetJSON()
Returns the JSON for this collection (as array).
public string GetJSON()Returns
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
- ItemT
- The element to add. 
- Keystring
- The key used for this element (optional). 
Returns
- Collection<T>
- This collection. 
Exceptions
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
- Indexobject
- 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
- Indexobject
- The index or key for the element to get. 
- DefaultValueT
- 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
- Indexobject
- 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
- Indexobject
- The index or key for the element to get. 
- pNewKeystring
- The new key to use. May be empty. 
Exceptions
- Exception
- Throws an error if the key is not unique.