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

public int Count { get; }

Property Value

int

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()

public void Clear()

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)

public void CopyTo(Array array, int index)

Parameters

array Array
index int

CopyTo(T[], int)

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

Parameters

array T[]
arrayIndex int

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)

public int IndexOf(T item)

Parameters

item T

Returns

int

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.