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>, IReadOnlyList<TItem>, IReadOnlyCollection<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

public virtual int Count { get; }

Property Value

int

IsInitialized

Gets a value indicating the list is initialized or not.

protected bool IsInitialized { get; }

Property Value

bool

IsReadOnly

public bool IsReadOnly { get; }

Property Value

bool

this[int]

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

Parameters

index int

Property Value

TItem

Items

Gets the underlying list.

protected IList<TItem> Items { get; }

Property Value

IList<TItem>

Methods

Add(TItem)

public void Add(TItem item)

Parameters

item TItem

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

public void Clear()

Contains(TItem)

public bool Contains(TItem item)

Parameters

item TItem

Returns

bool

CopyTo(TItem[], int)

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

Parameters

array TItem[]
arrayIndex int

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)

public int IndexOf(TItem item)

Parameters

item TItem

Returns

int

Initialize()

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

protected abstract void Initialize()

Insert(int, TItem)

public void Insert(int index, TItem item)

Parameters

index int
item TItem

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)

public bool Remove(TItem item)

Parameters

item TItem

Returns

bool

RemoveAt(int)

public void RemoveAt(int index)

Parameters

index int