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 ReferenceArray<T>
Represents an array of references to database objects.
Inherited Members
Namespace: VeloxDB.ObjectInterface
Assembly: vlxdb.dll
Syntax
public sealed class ReferenceArray<T> : ReferenceArray, IList<T>, ICollection<T>, IEnumerable<T>, IEnumerable where T : DatabaseObject
Type Parameters
| Name | Description |
|---|---|
| T | The type of items in the array. |
Remarks
VeloxDB allows you to specify an array like collection. ReferenceArray<T> can only hold references to DatabaseObject, if you need an array of references to simple types, use DatabaseArray<T>. ReferenceArray<T> property must be marked with DatabaseReferenceAttribute attribute because it represents a reference to another DatabaseObject.
ReferenceArray<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 ReferenceArray<T> amortized constant time adds, constant time direct access and linear remove.
Examples
The following example demonstrates how to declare a ReferenceArray<T> property.
[DatabaseClass]
[HashIndex("name", true, nameof(City.Name))]
public abstract class City : DatabaseObject
{
[DatabaseProperty]
public abstract string Name { get; set; }
[DatabaseReference]
public abstract ReferenceArray<WeatherStation> Stations {get; set;}
}
The following example demonstrates how to use a ReferenceArray<T>.
[DbAPIOperation]
public void CreateTestCity(ObjectModel om)
{
City city = om.CreateObject<City>();
city.Stations = new ReferenceArray<WeatherStation>();
WeatherStation ws;
for (int i = 0; i < 4; i++)
{
ws = om.CreateObject<WeatherStation>();
city.Stations.Add(ws);
}
// Get a WeatherStation by index
ws = city.Stations[2];
// Remove using object
city.Stations.Remove(ws);
// Remove using index
city.Stations.RemoveAt(0);
// Clear
city.Stations.Clear();
}
Constructors
ReferenceArray()
Creates a new empty instance of the ReferenceArray<T>.
Declaration
public ReferenceArray()
ReferenceArray(IEnumerable<T>)
Creates a new instance of the ReferenceArray<T> that contains elements copied from the supplied collection.
Declaration
public ReferenceArray(IEnumerable<T> collection)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<T> | collection | The collection whose elements are to be copied. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
| ArgumentException | If any item in |
ReferenceArray(int)
Creates a new empty instance of the ReferenceArray<T>. With specified capacity.
Declaration
public ReferenceArray(int capacity = 4)
Parameters
| Type | Name | Description |
|---|---|---|
| int | capacity | Initial capacity. The initial size of the backing array. |
Properties
Count
Gets the number of items contained in the ReferenceArray<T>.
Declaration
public override int Count { get; }
Property Value
| Type | Description |
|---|---|
| int |
Overrides
Exceptions
| Type | Condition |
|---|---|
| InvalidOperationException | If the parent object of the DatabaseArray<T> has been deleted or abandoned. |
| ObjectDisposedException | If the parent object of the DatabaseArray<T> has been disposed. |
IsReadOnly
Gets if the ReferenceArray<T> is Readonly. Always returns false.
Declaration
public bool IsReadOnly { get; }
Property Value
| Type | Description |
|---|---|
| bool |
this[int]
Index accessor.
Declaration
public T this[int index] { get; set; }
Parameters
| Type | Name | Description |
|---|---|---|
| int | index | Index of the item to get. |
Property Value
| Type | Description |
|---|---|
| T | Requested item. |
Exceptions
| Type | Condition |
|---|---|
| IndexOutOfRangeException | If |
| InvalidOperationException | If the parent object of the DatabaseArray<T> has been deleted or abandoned. |
| ObjectDisposedException | If the parent object of the DatabaseArray<T> has been disposed. |
Methods
Add(T)
Add an item to the end of the ReferenceArray<T>.
Declaration
public void Add(T item)
Parameters
| Type | Name | Description |
|---|---|---|
| T | item | The item to be added to the end of the ReferenceArray<T>. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
| InvalidOperationException | If the added item would cause Count to exceed |
| ObjectDisposedException | If the parent object of the ReferenceArray<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 |
|---|---|---|
| IEnumerable<T> | collection | Collection whose elements will be added. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
Clear()
Clears the ReferenceArray<T>.
Declaration
public void Clear()
Exceptions
| Type | Condition |
|---|---|
| InvalidOperationException | If the parent object of the ReferenceArray<T> has been deleted or abandoned. |
| ObjectDisposedException | If the parent object of the ReferenceArray<T> has been disposed. |
Contains(T)
Determines if an item is in the ReferenceArray<T>.
Declaration
public bool Contains(T item)
Parameters
| Type | Name | Description |
|---|---|---|
| T | item | The item to locate in the ReferenceArray<T>. |
Returns
| Type | Description |
|---|---|
| bool |
|
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
| InvalidOperationException | If the parent object of the ReferenceArray<T> has been deleted or abandoned. |
| ObjectDisposedException | If the parent object of the ReferenceArray<T> has been disposed. |
CopyTo(T[], int)
Copies all items from the ReferenceArray<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. |
| int | arrayIndex | Zero based index in |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
| ArgumentException | There is not enough space in |
| ArgumentOutOfRangeException |
|
| InvalidOperationException | If the parent object of the ReferenceArray<T> has been deleted or abandoned. |
| ObjectDisposedException | If the parent object of the ReferenceArray<T> has been disposed. |
GetEnumerator()
Returns an enumerator that iterates through ReferenceArray<T>.
Declaration
public IEnumerator<T> GetEnumerator()
Returns
| Type | Description |
|---|---|
| IEnumerator<T> | An enumerator. |
Remarks
If ReferenceArray<T> changes, enumerator is invalidated. Any attempts to use it after that will throw an InvalidOperationException.
Exceptions
| Type | Condition |
|---|---|
| InvalidOperationException | If the parent object of the ReferenceArray<T> has been deleted or abandoned. |
| ObjectDisposedException | If the parent object of the ReferenceArray<T> has been disposed. |
IndexOf(T)
Finds an item in the ReferenceArray<T> and returns its position.
Declaration
public int IndexOf(T item)
Parameters
| Type | Name | Description |
|---|---|---|
| T | item | Item to find in ReferenceArray<T>. |
Returns
| Type | Description |
|---|---|
| int | If the element is found, it return the zero based index in ReferenceArray<T>, otherwise it returns -1. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
| InvalidOperationException | If the parent object of the ReferenceArray<T> has been deleted or abandoned. |
| ObjectDisposedException | If the parent object of the ReferenceArray<T> has been disposed. |
Insert(int, T)
Inserts an item into ReferenceArray<T> at the specified position.
Declaration
public void Insert(int index, T item)
Parameters
| Type | Name | Description |
|---|---|---|
| int | index | Zero based position at which to insert |
| T | item | The item to insert. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
| ArgumentOutOfRangeException | If |
| InvalidOperationException | If the parent object of the ReferenceArray<T> has been deleted or abandoned. |
| ObjectDisposedException | If the parent object of the ReferenceArray<T> has been disposed. |
Remove(T)
Remove the first occurrence of the item from the ReferenceArray<T>.
Declaration
public bool Remove(T item)
Parameters
| Type | Name | Description |
|---|---|---|
| T | item | Item to be removed. |
Returns
| Type | Description |
|---|---|
| bool |
|
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
| InvalidOperationException | If the parent object of the ReferenceArray<T> has been deleted or abandoned. |
| ObjectDisposedException | If the parent object of the ReferenceArray<T> has been disposed. |
RemoveAt(int)
Remove an item at the given position.
Declaration
public void RemoveAt(int index)
Parameters
| Type | Name | Description |
|---|---|---|
| int | index | Zero based index of an item to remove. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | If |
| InvalidOperationException | If the parent object of the DatabaseArray<T> has been deleted or abandoned. |
| ObjectDisposedException | If the parent object of the DatabaseArray<T> has been disposed. |