Class Collection<T, TCollection>
A collection of values.
Inheritance
Namespace: FM.LiveSwitch
Assembly: FM.LiveSwitch.dll
Syntax
public abstract class Collection<T, TCollection> : object where TCollection : Collection<T, TCollection>
Type Parameters
Name | Description |
---|---|
T | |
TCollection |
Constructors
Collection()
Initializes a new instance of the Collection<T, TCollection> class.
Declaration
public Collection()
Properties
Count
Gets the count.
Declaration
public int Count { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
Value
Gets or sets the value.
Declaration
public T Value { get; set; }
Property Value
Type | Description |
---|---|
T |
Values
Gets or sets the values.
Declaration
public T[] Values { get; set; }
Property Value
Type | Description |
---|---|
T[] |
Methods
Add(T)
Adds a value.
Declaration
public virtual bool Add(T value)
Parameters
Type | Name | Description |
---|---|---|
T | value | The value. |
Returns
Type | Description |
---|---|
System.Boolean |
AddMany(T[])
Adds some values.
Declaration
public void AddMany(T[] values)
Parameters
Type | Name | Description |
---|---|---|
T[] | values | The values. |
AddSuccess(T)
Invoked when an element is added to the collection.
Declaration
protected virtual void AddSuccess(T value)
Parameters
Type | Name | Description |
---|---|---|
T | value | The value. |
AddSuccessNoLock(T)
Invoked after an element is added to the collection.
Declaration
protected virtual void AddSuccessNoLock(T value)
Parameters
Type | Name | Description |
---|---|---|
T | value | The value. |
Any()
Determined whether the collection contains at least one value.
Declaration
public bool Any()
Returns
Type | Description |
---|---|
System.Boolean |
Any(Function1<T, Boolean>)
Determined whether the collection contains at least one value that matches the specified predicate.
Declaration
public bool Any(Function1<T, bool> predicate)
Parameters
Type | Name | Description |
---|---|---|
Function1<T, System.Boolean> | predicate | The predicate. |
Returns
Type | Description |
---|---|
System.Boolean |
ArrayFromList(List<T>)
Creates an array from a list.
Declaration
protected abstract T[] ArrayFromList(List<T> list)
Parameters
Type | Name | Description |
---|---|---|
List<T> | list | The list. |
Returns
Type | Description |
---|---|
T[] |
Contains(T)
Determines whether the collection contains a value.
Declaration
public bool Contains(T value)
Parameters
Type | Name | Description |
---|---|---|
T | value | The value. |
Returns
Type | Description |
---|---|
System.Boolean |
CreateCollection()
Creates a collection.
Declaration
protected abstract TCollection CreateCollection()
Returns
Type | Description |
---|---|
TCollection |
First()
Gets the first value. Throws an exception if there are no values in the collection.
Declaration
public T First()
Returns
Type | Description |
---|---|
T |
First(Function1<T, Boolean>)
Gets the first value that matches the specified predicate. Throws an exception if there are no such values in the collection.
Declaration
public T First(Function1<T, bool> predicate)
Parameters
Type | Name | Description |
---|---|---|
Function1<T, System.Boolean> | predicate | The predicate. |
Returns
Type | Description |
---|---|
T |
FirstOrDefault()
Gets the first value. Returns a default value if there are no values in the collection.
Declaration
public T FirstOrDefault()
Returns
Type | Description |
---|---|
T |
FirstOrDefault(Function1<T, Boolean>)
Gets the first value that matches the specified predicate. Returns a default value if there are no such values in the collection.
Declaration
public T FirstOrDefault(Function1<T, bool> predicate)
Parameters
Type | Name | Description |
---|---|---|
Function1<T, System.Boolean> | predicate | The predicate. |
Returns
Type | Description |
---|---|
T |
ForEach(Action2<T, Int32>)
Executes a callback function once per value.
Declaration
public void ForEach(Action2<T, int> callback)
Parameters
Type | Name | Description |
---|---|---|
Action2<T, System.Int32> | callback | The callback to execute. |
Last()
Gets the last value. Throws an exception if there are no values in the collection.
Declaration
public T Last()
Returns
Type | Description |
---|---|
T |
Last(Function1<T, Boolean>)
Gets the last value that matches the specified predicate. Throws an exception if there are no such values in the collection.
Declaration
public T Last(Function1<T, bool> predicate)
Parameters
Type | Name | Description |
---|---|---|
Function1<T, System.Boolean> | predicate | The predicate. |
Returns
Type | Description |
---|---|
T |
LastOrDefault()
Gets the last value. Returns a default value if there are no values in the collection.
Declaration
public T LastOrDefault()
Returns
Type | Description |
---|---|
T |
LastOrDefault(Function1<T, Boolean>)
Gets the last value that matches the specified predicate. Returns a default value if there are no such values in the collection.
Declaration
public T LastOrDefault(Function1<T, bool> predicate)
Parameters
Type | Name | Description |
---|---|---|
Function1<T, System.Boolean> | predicate | The predicate. |
Returns
Type | Description |
---|---|
T |
Remove(T)
Removes a value.
Declaration
public bool Remove(T value)
Parameters
Type | Name | Description |
---|---|---|
T | value | The value. |
Returns
Type | Description |
---|---|
System.Boolean |
RemoveAll()
Removes all values.
Declaration
public virtual void RemoveAll()
RemoveFirst()
Removes the first value.
Declaration
public T RemoveFirst()
Returns
Type | Description |
---|---|
T |
RemoveFirst(Function1<T, Boolean>)
Removes the first value that matches a given condition.
Declaration
public T RemoveFirst(Function1<T, bool> condition)
Parameters
Type | Name | Description |
---|---|---|
Function1<T, System.Boolean> | condition |
Returns
Type | Description |
---|---|
T |
RemoveLast()
Removes the last value.
Declaration
public T RemoveLast()
Returns
Type | Description |
---|---|
T |
RemoveLast(Function1<T, Boolean>)
Removes the last value that matches a given condition.
Declaration
public T RemoveLast(Function1<T, bool> condition)
Parameters
Type | Name | Description |
---|---|---|
Function1<T, System.Boolean> | condition |
Returns
Type | Description |
---|---|
T |
RemoveMany(T[])
Removes some values.
Declaration
public void RemoveMany(T[] values)
Parameters
Type | Name | Description |
---|---|---|
T[] | values | The values. |
RemoveSuccess(T)
Invoked when an element is removed from the collection.
Declaration
protected virtual void RemoveSuccess(T value)
Parameters
Type | Name | Description |
---|---|---|
T | value | The value. |
RemoveSuccessNoLock(T)
Invoked after an element is removed from the collection.
Declaration
protected virtual void RemoveSuccessNoLock(T value)
Parameters
Type | Name | Description |
---|---|---|
T | value | The value. |
Replace(T[])
Replaces the collection with a new set of values.
Declaration
public void Replace(T[] values)
Parameters
Type | Name | Description |
---|---|---|
T[] | values | The values. |
Single()
Gets the only value. Throws an exception if there are no values or more than one value in the collection.
Declaration
public T Single()
Returns
Type | Description |
---|---|
T |
Single(Function1<T, Boolean>)
Gets the only value that matches the specified predicate. Throws an exception if there are no values or more than one value in the collection.
Declaration
public T Single(Function1<T, bool> predicate)
Parameters
Type | Name | Description |
---|---|---|
Function1<T, System.Boolean> | predicate |
Returns
Type | Description |
---|---|
T |
SingleOrDefault()
Gets the only value. Returns a default value if there are no values or more than one value in the collection.
Declaration
public T SingleOrDefault()
Returns
Type | Description |
---|---|
T |
SingleOrDefault(Function1<T, Boolean>)
Gets the only value that matches the specified predicate. Returns a default value if there are no values or more than one value in the collection.
Declaration
public T SingleOrDefault(Function1<T, bool> predicate)
Parameters
Type | Name | Description |
---|---|---|
Function1<T, System.Boolean> | predicate |
Returns
Type | Description |
---|---|
T |
ToArray()
Clones the values into a new array.
Declaration
public T[] ToArray()
Returns
Type | Description |
---|---|
T[] |
ValueAt(Int32)
Gets the value at the specified index. Throws an exception if a value does not exist at that index.
Declaration
public T ValueAt(int index)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | The index. |
Returns
Type | Description |
---|---|
T |
ValueAtOrDefault(Int32)
Gets the value at the specified index. Returns a default value if a value does not exist at that index.
Declaration
public T ValueAtOrDefault(int index)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | The index. |
Returns
Type | Description |
---|---|
T |
Where(Function2<T, Int32, Boolean>)
Creates a new collection with values that match the specified predicate.
Declaration
public TCollection Where(Function2<T, int, bool> predicate)
Parameters
Type | Name | Description |
---|---|---|
Function2<T, System.Int32, System.Boolean> | predicate | The predicate. |
Returns
Type | Description |
---|---|
TCollection |