Class OwnedCollection<TOwner, TItem>
- Namespace
- AsmResolver.Collections
- Assembly
- AsmResolver.dll
Represents an indexed collection where each element is owned by some object, and prevents the element from being added to any other instance of the collection.
public class OwnedCollection<TOwner, TItem> : LazyList<TItem>, IList<TItem>, ICollection<TItem>, IReadOnlyList<TItem>, IReadOnlyCollection<TItem>, IEnumerable<TItem>, IEnumerable where TOwner : class where TItem : class, IOwnedCollectionElement<TOwner>
Type Parameters
TOwnerThe type of the owner object.
TItemThe type of elements to store.
- Inheritance
-
LazyList<TItem>OwnedCollection<TOwner, TItem>
- Implements
-
IList<TItem>ICollection<TItem>IReadOnlyList<TItem>IReadOnlyCollection<TItem>IEnumerable<TItem>
- Inherited Members
Constructors
OwnedCollection(TOwner)
Creates a new empty collection that is owned by an object.
public OwnedCollection(TOwner owner)
Parameters
ownerTOwnerThe owner of the collection.
OwnedCollection(TOwner, int)
Creates a new empty collection that is owned by an object.
public OwnedCollection(TOwner owner, int capacity)
Parameters
ownerTOwnerThe owner of the collection.
capacityintThe initial number of elements the collection can store.
Properties
Owner
Gets the owner of the collection.
public TOwner Owner { get; }
Property Value
- TOwner
Methods
AssertNotNullAndHasNoOwner(TItem?)
Verifies that the provided item is not null and not added to another list.
protected void AssertNotNullAndHasNoOwner(TItem? item)
Parameters
itemTItemThe item to verify.
Exceptions
- ArgumentNullException
Occurs when the item is null.
- ArgumentException
Occurs when the item is already owned by another collection.
Initialize()
Initializes the list. This method is called in a thread-safe manner.
protected override void Initialize()
OnClearItems()
The method that gets called upon clearing the entire list.
protected override void OnClearItems()
OnInsertItem(int, TItem)
The method that gets called upon inserting a new item in the list.
protected override 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 override 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 override 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 override void OnSetItem(int index, TItem item)
Parameters
indexintThe index that is being replaced.
itemTItemThe new item.