note
VeloxDB is still in beta and APIs are subject to change. We are in the process of completing the documentation, so some sections may be incomplete or empty at this time.
Class DatabaseArray<T>
Represents a strongly typed array of simple types.
Implements
Namespace: VeloxDB.ObjectInterface
Assembly: vlxdb.dll
Syntax
public abstract class DatabaseArray<T> : DatabaseArray
Type Parameters
Name | Description |
---|---|
T | The type of elements in the array. |
Remarks
VeloxDB allows you to specify an array like collection. DatabaseArray<T> can only hold simple types, if you need an array of references to other DatabaseObjects, use ReferenceArray<T>.
DatabaseArray<T> is backed by an array. Array's size is initially set to capacity. As long as the capacity is larger than the length of the array Add is constant time operation (O(1)). When there is no more space in the backing array new array is allocated. The new array is twice the size of the previous one. Contents of the old array are copied to the new array. This gives DatabaseArray<T> amortized constant time adds, constant time direct access and linear remove.
Examples
The following example demonstrates how to declare a DatabaseArray<T> property.
[DatabaseClass]
public abstract class WeatherStation : DatabaseObject
{
[DatabaseProperty]
public abstract double Lat { get; set; }
[DatabaseProperty]
public abstract double Long { get; set; }
[DatabaseProperty]
public abstract DatabaseArray<double> Temperature { get; set; }
[DatabaseProperty]
public abstract DatabaseArray<DateTime> Dates { get; set; }
}
The following example demonstrates how to use a DatabaseArray<T>.
[DbAPIOperation]
public void CreateTestStation(ObjectModel om)
{
WeatherStation ws = om.CreateObject<WeatherStation>();
// Create an empty array
ws.Dates = DatabaseArray<DateTime>.Create(4);
// Add new dates to the end
ws.Dates.Add(new DateTime(2022, 7, 1));
ws.Dates.Add(new DateTime(2022, 7, 2));
ws.Dates.Add(new DateTime(2022, 7, 3));
ws.Dates.Add(new DateTime(2022, 7, 4));
// Create an array from an existing collection
ws.Temperature = DatabaseArray<double>.Create(new double[] { 33, 39, 41, 34 });
// Remove by value
ws.Temperature.Remove(41);
// Remove using index
ws.Temperature.RemoveAt(2);
// Clear
ws.Temperature.Clear();
ws.Dates.Clear();
}
Properties
Count
Gets the number of items contained in the DatabaseArray<T>.
Declaration
public int Count { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
IsReadOnly
Gets if the DatabaseArray<T> is Readonly. Always returns false.
Declaration
public bool IsReadOnly { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Item[Int32]
Index accessor.
Declaration
public abstract T this[int index] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | Index of the item to get. |
Property Value
Type | Description |
---|---|
T | Requested item. |
Exceptions
Type | Condition |
---|---|
System.IndexOutOfRangeException | If |
System.InvalidOperationException | If the parent object of the DatabaseArray<T> has been deleted or abandoned. |
System.ObjectDisposedException | If the parent object of the DatabaseArray<T> has been disposed. |
Methods
Add(T)
Add an item to the end of the DatabaseArray<T>.
Declaration
public void Add(T item)
Parameters
Type | Name | Description |
---|---|---|
T | item | The item to be added to the end of the DatabaseArray<T>. |
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | If the added item would cause Count to exceed |
System.ObjectDisposedException | If the parent object of the DatabaseArray<T> has been disposed. |
AddRange(IEnumerable<T>)
Adds the elements of the specified collection to the end of the DatabaseArray<T>.
Declaration
public void AddRange(IEnumerable<T> collection)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<T> | collection | Collection whose elements will be added. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
System.InvalidOperationException | If the adding |
System.ObjectDisposedException | If the parent object of the DatabaseArray<T> has been disposed. |
Clear()
Clears the DatabaseArray<T>.
Declaration
public void Clear()
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | If the parent object of the DatabaseArray<T> has been deleted or abandoned. |
System.ObjectDisposedException | If the parent object of the DatabaseArray<T> has been disposed. |
Contains(T)
Determines if an item is in the DatabaseArray<T>.
Declaration
public bool Contains(T item)
Parameters
Type | Name | Description |
---|---|---|
T | item | The item to locate in the DatabaseArray<T>. |
Returns
Type | Description |
---|---|
System.Boolean |
|
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | If the parent object of the DatabaseArray<T> has been deleted or abandoned. |
System.ObjectDisposedException | If the parent object of the DatabaseArray<T> has been disposed. |
CopyTo(T[], Int32)
Copies all items from the DatabaseArray<T> to the given array, starting at the specified index of the target array.
Declaration
public void CopyTo(T[] array, int arrayIndex)
Parameters
Type | Name | Description |
---|---|---|
T[] | array | Destination array. |
System.Int32 | arrayIndex | Zero based index in |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
System.ArgumentException | There is not enough space in |
System.ArgumentOutOfRangeException |
|
System.InvalidOperationException | If the parent object of the DatabaseArray<T> has been deleted or abandoned. |
System.ObjectDisposedException | If the parent object of the DatabaseArray<T> has been disposed. |
Create()
Creates a new empty instance of the DatabaseArray<T>.
Declaration
public static DatabaseArray<T> Create()
Returns
Type | Description |
---|---|
DatabaseArray<T> | Created DatabaseArray<T> |
Create(IEnumerable<T>)
Creates a new instance of the DatabaseArray<T> that contains elements copied from the supplied collection.
Declaration
public static DatabaseArray<T> Create(IEnumerable<T> collection)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<T> | collection | The collection whose elements are to be copied. |
Returns
Type | Description |
---|---|
DatabaseArray<T> | Created DatabaseArray<T> |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
Create(Int32)
Creates a new empty instance of the DatabaseArray<T>. With specified capacity.
Declaration
public static DatabaseArray<T> Create(int capacity)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | capacity | Initial capacity. The initial size of the backing array. |
Returns
Type | Description |
---|---|
DatabaseArray<T> | Created DatabaseArray<T> |
GetEnumerator()
Returns an enumerator that iterates through DatabaseArray<T>.
Declaration
public IEnumerator<T> GetEnumerator()
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerator<T> | An enumerator. |
Remarks
If DatabaseArray<T> changes, enumerator is invalidated. Any attempts to use it after that will throw an System.InvalidOperationException.
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | If the parent object of the DatabaseArray<T> has been deleted or abandoned. |
System.ObjectDisposedException | If the parent object of the DatabaseArray<T> has been disposed. |
IndexOf(T)
Finds an item in the DatabaseArray<T> and returns its position.
Declaration
public int IndexOf(T item)
Parameters
Type | Name | Description |
---|---|---|
T | item | Item to find in DatabaseArray<T>. |
Returns
Type | Description |
---|---|
System.Int32 | If the element is found, it return the zero based index in DatabaseArray<T>, otherwise it returns -1. |
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | If the parent object of the DatabaseArray<T> has been deleted or abandoned. |
System.ObjectDisposedException | If the parent object of the DatabaseArray<T> has been disposed. |
Insert(Int32, T)
Inserts an item into DatabaseArray<T> at the specified position.
Declaration
public void Insert(int index, T item)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | Zero based position at which to insert |
T | item | The item to insert. |
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException | If |
System.InvalidOperationException | If the parent object of the DatabaseArray<T> has been deleted or abandoned. |
System.ObjectDisposedException | If the parent object of the DatabaseArray<T> has been disposed. |
Remove(T)
Remove the first occurrence of the item from the DatabaseArray<T>.
Declaration
public bool Remove(T item)
Parameters
Type | Name | Description |
---|---|---|
T | item | Item to be removed. |
Returns
Type | Description |
---|---|
System.Boolean |
|
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | If the parent object of the DatabaseArray<T> has been deleted or abandoned. |
System.ObjectDisposedException | If the parent object of the DatabaseArray<T> has been disposed. |
RemoveAt(Int32)
Remove an item at the given position.
Declaration
public void RemoveAt(int index)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | Zero based index of an item to remove. |
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException | If |
System.InvalidOperationException | If the parent object of the DatabaseArray<T> has been deleted or abandoned. |
System.ObjectDisposedException | If the parent object of the DatabaseArray<T> has been disposed. |