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
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
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
indexintThe zero-based index of the element to get or set.
Property Value
- TItem
The element at the specified index.
Exceptions
- ArgumentOutOfRangeException
indexis 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
itemTItemThe 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
itemsIEnumerable<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
itemTItemThe object to locate in the ICollection<T>.
Returns
- bool
true if
itemis 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
arrayTItem[]The one-dimensional Array that is the destination of the elements copied from ICollection<T>. The Array must have zero-based indexing.
arrayIndexintThe zero-based index in
arrayat which copying begins.
Exceptions
- ArgumentNullException
arrayis null.- ArgumentOutOfRangeException
arrayIndexis less than 0.- ArgumentException
The number of elements in the source ICollection<T> is greater than the available space from
arrayIndexto the end of the destinationarray.
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
itemTItemThe object to locate in the IList<T>.
Returns
- int
The index of
itemif 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
indexintThe zero-based index at which
itemshould be inserted.itemTItemThe object to insert into the IList<T>.
Exceptions
- ArgumentOutOfRangeException
indexis 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
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)
Removes the first occurrence of a specific object from the ICollection<T>.
public bool Remove(TItem item)
Parameters
itemTItemThe object to remove from the ICollection<T>.
Returns
- bool
true if
itemwas successfully removed from the ICollection<T>; otherwise, false. This method also returns false ifitemis 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
indexintThe zero-based index of the item to remove.
Exceptions
- ArgumentOutOfRangeException
indexis not a valid index in the IList<T>.- NotSupportedException
The IList<T> is read-only.