Table of Contents

Class LazyList<TItem>

Namespace
AsmResolver.Collections
Assembly
AsmResolver.dll

Provides a base for lists that are lazy initialized.

public abstract class LazyList<TItem> : IList<TItem>, ICollection<TItem>, IEnumerable<TItem>, IEnumerable

Type Parameters

TItem

The type of elements the list stores.

Inheritance
LazyList<TItem>
Implements
IList<TItem>
Derived
Inherited Members

Constructors

LazyList()

Creates a new, empty, uninitialized list.

public LazyList()

LazyList(int)

Creates a new, empty, uninitialized list.

public LazyList(int capacity)

Parameters

capacity int

The initial number of elements the list can store.

Properties

Capacity

Gets or sets the total number of elements the list can contain before it has to resize its internal buffer.

public int Capacity { get; set; }

Property Value

int

Count

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

public virtual int Count { get; }

Property Value

int

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

IsInitialized

Gets a value indicating the list is initialized or not.

protected bool IsInitialized { get; }

Property Value

bool

IsReadOnly

Gets a value indicating whether the ICollection<T> is read-only.

public bool IsReadOnly { get; }

Property Value

bool

true if the ICollection<T> is read-only; otherwise, false.

this[int]

Gets or sets the element at the specified index.

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

Parameters

index int

The zero-based index of the element to get or set.

Property Value

TItem

The element at the specified index.

Exceptions

ArgumentOutOfRangeException

index is not a valid index in the IList<T>.

NotSupportedException

The property is set and the IList<T> is read-only.

Items

Gets the underlying list.

protected IList<TItem> Items { get; }

Property Value

IList<TItem>

Methods

Add(TItem)

Adds an item to the ICollection<T>.

public void Add(TItem item)

Parameters

item TItem

The object to add to the ICollection<T>.

Exceptions

NotSupportedException

The ICollection<T> is read-only.

AddRange(IEnumerable<TItem>)

Appends the elements of a collection to the end of the LazyList<TItem>.

public void AddRange(IEnumerable<TItem> items)

Parameters

items IEnumerable<TItem>

The items to append.

Clear()

Removes all items from the ICollection<T>.

public void Clear()

Exceptions

NotSupportedException

The ICollection<T> is read-only.

Contains(TItem)

Determines whether the ICollection<T> contains a specific value.

public bool Contains(TItem item)

Parameters

item TItem

The object to locate in the ICollection<T>.

Returns

bool

true if item is found in the ICollection<T>; otherwise, false.

CopyTo(TItem[], int)

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

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

Parameters

array TItem[]

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.

GetEnumerator()

Returns an enumerator that enumerates the lazy list.

public LazyList<TItem>.Enumerator GetEnumerator()

Returns

LazyList<TItem>.Enumerator

The enumerator.

Remarks

This enumerator only ensures the list is initialized upon calling the MoveNext() method.

IndexOf(TItem)

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

public int IndexOf(TItem item)

Parameters

item TItem

The object to locate in the IList<T>.

Returns

int

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

Initialize()

Initializes the list. This method is called in a thread-safe manner.

protected abstract void Initialize()

Insert(int, TItem)

Inserts an item to the IList<T> at the specified index.

public void Insert(int index, TItem item)

Parameters

index int

The zero-based index at which item should be inserted.

item TItem

The object to insert into the IList<T>.

Exceptions

ArgumentOutOfRangeException

index is not a valid index in the IList<T>.

NotSupportedException

The IList<T> is read-only.

OnClearItems()

The method that gets called upon clearing the entire list.

protected virtual void OnClearItems()

OnInsertItem(int, TItem)

The method that gets called upon inserting a new item in the list.

protected virtual void OnInsertItem(int index, TItem item)

Parameters

index int

The index where the item is inserted at.

item TItem

The new item.

OnInsertRange(int, IEnumerable<TItem>)

The method that gets called upon inserting a collection of new items in the list.

protected virtual void OnInsertRange(int index, IEnumerable<TItem> items)

Parameters

index int

The index where the item is inserted at.

items IEnumerable<TItem>

The new items.

OnRemoveItem(int)

The method that gets called upon removing an item.

protected virtual void OnRemoveItem(int index)

Parameters

index int

The index of the element to remove.

OnSetItem(int, TItem)

The method that gets called upon replacing an item in the list.

protected virtual void OnSetItem(int index, TItem item)

Parameters

index int

The index that is being replaced.

item TItem

The new item.

PostInitialize()

Performs any final adjustments to the collection after all initial items were added to the underlying list.

protected virtual void PostInitialize()

Remarks

Upon calling this method, the IsInitialized has already been set to true, but the initialization lock has not been released yet. This means that any element in the list is guaranteed to be still in its initial state. It is therefore safe to access elements, as well as adding or removing items from Items.

Remove(TItem)

Removes the first occurrence of a specific object from the ICollection<T>.

public bool Remove(TItem item)

Parameters

item TItem

The object to remove from the ICollection<T>.

Returns

bool

true if item was successfully removed from the ICollection<T>; otherwise, false. This method also returns false if item is not found in the original ICollection<T>.

Exceptions

NotSupportedException

The ICollection<T> is read-only.

RemoveAt(int)

Removes the IList<T> item at the specified index.

public void RemoveAt(int index)

Parameters

index int

The zero-based index of the item to remove.

Exceptions

ArgumentOutOfRangeException

index is not a valid index in the IList<T>.

NotSupportedException

The IList<T> is read-only.