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
TItemThe type of elements the list stores.
- Inheritance
-
LazyList<TItem>
- Implements
-
IList<TItem>ICollection<TItem>IReadOnlyList<TItem>IReadOnlyCollection<TItem>IEnumerable<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
capacityintThe 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
Count
public virtual int Count { get; }
Property Value
IsInitialized
Gets a value indicating the list is initialized or not.
protected bool IsInitialized { get; }
Property Value
IsReadOnly
public bool IsReadOnly { get; }
Property Value
this[int]
public TItem this[int index] { get; set; }
Parameters
indexint
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
itemTItem
AddRange(IEnumerable<TItem>)
Appends the elements of a collection to the end of the LazyList<TItem>.
public void AddRange(IEnumerable<TItem> items)
Parameters
itemsIEnumerable<TItem>The items to append.
Clear()
public void Clear()
Contains(TItem)
public bool Contains(TItem item)
Parameters
itemTItem
Returns
CopyTo(TItem[], int)
public void CopyTo(TItem[] array, int arrayIndex)
Parameters
arrayTItem[]arrayIndexint
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
itemTItem
Returns
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
indexintitemTItem
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
indexintThe index where the item is inserted at.
itemTItemThe 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
indexintThe index where the item is inserted at.
itemsIEnumerable<TItem>The new items.
OnRemoveItem(int)
The method that gets called upon removing an item.
protected virtual void OnRemoveItem(int index)
Parameters
indexintThe 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
indexintThe index that is being replaced.
itemTItemThe 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
itemTItem
Returns
RemoveAt(int)
public void RemoveAt(int index)
Parameters
indexint