Class RefList<T>
- Namespace
- AsmResolver.Collections
- Assembly
- AsmResolver.dll
Provides an implementation of a collection for which the raw elements can be accessed by-reference. This allows for dynamically sized lists that work on mutable structs.
public class RefList<T> : ICollection, IList<T>, ICollection<T>, IReadOnlyList<T>, IReadOnlyCollection<T>, IEnumerable<T>, IEnumerable where T : struct
Type Parameters
TThe type of elements to store.
- Inheritance
-
RefList<T>
- Implements
-
IList<T>ICollection<T>IEnumerable<T>
- Inherited Members
Remarks
This list should be regarded as a mutable array that is not thread-safe.
Constructors
RefList()
Creates a new empty list with the default capacity.
public RefList()
RefList(int)
Creates a new empty list with the provided capacity.
public RefList(int capacity)
Parameters
capacityintThe capacity of the list.
Fields
DefaultCapacity
Gets the default capacity of a ref-list.
public const int DefaultCapacity = 4
Field Value
Properties
Capacity
Gets or sets the total number of elements that the underlying array can store.
public int Capacity { get; set; }
Property Value
Count
public int Count { get; }
Property Value
this[int]
Gets or sets an individual element within the list.
public T this[int index] { get; set; }
Parameters
indexintThe index of the element to access.
Property Value
- T
Exceptions
- IndexOutOfRangeException
Occurs when
indexis not a valid index within the array.
Version
Gets a number indicating the current version of the list.
public int Version { get; }
Property Value
Remarks
This number is incremented each time the underlying array is resized or when an element is replaced. It can also be used to verify that the reference returned by GetElementRef(int, out int) is still referencing an element in the current array.
Methods
Add(in T)
Adds an element to the end of the list.
public void Add(in T item)
Parameters
itemTThe element.
Clear()
public void Clear()
Contains(in T)
Determines whether an item is present in the reference list.
public bool Contains(in T item)
Parameters
itemTThe item.
Returns
- bool
trueif the element is present,falseotherwise.
CopyTo(Array, int)
public void CopyTo(Array array, int index)
Parameters
CopyTo(T[], int)
public void CopyTo(T[] array, int arrayIndex)
Parameters
arrayT[]arrayIndexint
GetElementRef(int)
Gets an element within the list by reference.
public ref T GetElementRef(int index)
Parameters
indexintThe index of the element to access.
Returns
- T
A reference to the element.
Exceptions
- IndexOutOfRangeException
Occurs when
indexis not a valid index within the array.
GetElementRef(int, out int)
Gets an element within the list by reference.
public ref T GetElementRef(int index, out int version)
Parameters
indexintThe index of the element to access.
versionintThe version of the list upon obtaining the reference.
Returns
- T
A reference to the element.
Exceptions
- IndexOutOfRangeException
Occurs when
indexis not a valid index within the array.
GetEnumerator()
Returns an enumerator that iterates all elements in the list.
public RefList<T>.Enumerator GetEnumerator()
Returns
IndexOf(T)
public int IndexOf(T item)
Parameters
itemT
Returns
IndexOf(in T)
Determines the first index within the list that contains the provided element.
public int IndexOf(in T item)
Parameters
itemTThe element to search.
Returns
- int
The index, or -1 if the element is not present in the list.
Insert(int, in T)
Inserts an element into the list at the provided index.
public void Insert(int index, in T item)
Parameters
indexintThe index to insert into.
itemTThe element to insert.
Remove(in T)
Removes an element from the list.
public bool Remove(in T item)
Parameters
itemTThe element to remove.
Returns
- bool
trueif the element was removed successfully,falseotherwise.
RemoveAt(int)
Removes a single element from the list at the provided index.
public void RemoveAt(int index)
Parameters
indexintThe index of the element to remove.
Exceptions
- ArgumentOutOfRangeException
Occurs when the provided index is invalid.