Table of Contents

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

T

The type of elements to store.

Inheritance
RefList<T>
Implements
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

capacity int

The capacity of the list.

Fields

DefaultCapacity

Gets the default capacity of a ref-list.

public const int DefaultCapacity = 4

Field Value

int

Properties

Capacity

Gets or sets the total number of elements that the underlying array can store.

public int Capacity { get; set; }

Property Value

int

Count

Gets the number of elements contained in the ICollection<T>.

public int Count { get; }

Property Value

int

The number of elements contained in the ICollection<T>.

this[int]

Gets or sets an individual element within the list.

public T this[int index] { get; set; }

Parameters

index int

The index of the element to access.

Property Value

T

Exceptions

IndexOutOfRangeException

Occurs when index is not a valid index within the array.

Version

Gets a number indicating the current version of the list.

public int Version { get; }

Property Value

int

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

item T

The element.

Clear()

Removes all items from the ICollection<T>.

public void Clear()

Exceptions

NotSupportedException

The ICollection<T> is read-only.

Contains(in T)

Determines whether an item is present in the reference list.

public bool Contains(in T item)

Parameters

item T

The item.

Returns

bool

true if the element is present, false otherwise.

CopyTo(Array, int)

Copies the elements of the ICollection to an Array, starting at a particular Array index.

public void CopyTo(Array array, int index)

Parameters

array Array

The one-dimensional Array that is the destination of the elements copied from ICollection. The Array must have zero-based indexing.

index int

The zero-based index in array at which copying begins.

Exceptions

ArgumentNullException

array is null.

ArgumentOutOfRangeException

index is less than zero.

ArgumentException

array is multidimensional.

-or-

The number of elements in the source ICollection is greater than the available space from index to the end of the destination array.

-or-

The type of the source ICollection cannot be cast automatically to the type of the destination array.

CopyTo(T[], int)

Copies the elements of the ICollection<T> to an Array, starting at a particular Array index.

public void CopyTo(T[] array, int arrayIndex)

Parameters

array T[]

The one-dimensional Array that is the destination of the elements copied from ICollection<T>. The Array must have zero-based indexing.

arrayIndex int

The zero-based index in array at which copying begins.

Exceptions

ArgumentNullException

array is null.

ArgumentOutOfRangeException

arrayIndex is less than 0.

ArgumentException

The number of elements in the source ICollection<T> is greater than the available space from arrayIndex to the end of the destination array.

GetElementRef(int)

Gets an element within the list by reference.

public ref T GetElementRef(int index)

Parameters

index int

The index of the element to access.

Returns

T

A reference to the element.

Exceptions

IndexOutOfRangeException

Occurs when index is 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

index int

The index of the element to access.

version int

The version of the list upon obtaining the reference.

Returns

T

A reference to the element.

Exceptions

IndexOutOfRangeException

Occurs when index is not a valid index within the array.

GetEnumerator()

Returns an enumerator that iterates all elements in the list.

public RefList<T>.Enumerator GetEnumerator()

Returns

RefList<T>.Enumerator

IndexOf(T)

Determines the index of a specific item in the IList<T>.

public int IndexOf(T item)

Parameters

item T

The object to locate in the IList<T>.

Returns

int

The index of item if found in the list; otherwise, -1.

IndexOf(in T)

Determines the first index within the list that contains the provided element.

public int IndexOf(in T item)

Parameters

item T

The 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

index int

The index to insert into.

item T

The element to insert.

Remove(in T)

Removes an element from the list.

public bool Remove(in T item)

Parameters

item T

The element to remove.

Returns

bool

true if the element was removed successfully, false otherwise.

RemoveAt(int)

Removes a single element from the list at the provided index.

public void RemoveAt(int index)

Parameters

index int

The index of the element to remove.

Exceptions

ArgumentOutOfRangeException

Occurs when the provided index is invalid.