BaseCollection
Represents a base class for a generic collection with event notifications and inner collection management.
実装: ICollection<T>, IEnumerable<T>, IEnumerable, ICollection, INotifyList<T>, INotifyCollection<T>, IList<T>, IList
コンストラクター
protected BaseCollection(TCollection innerCollection)
baseCollection = BaseCollection(innerCollection)
Initializes a new instance of the BaseCollection class with the specified inner collection.
- innerCollection
- The inner collection to manage.
プロパティ
public bool CheckNullableItems { get; set; }
value = baseCollection.CheckNullableItems
baseCollection.CheckNullableItems = value
Gets or sets a value indicating whether to check for null items in the collection.
public virtual int Count { get; }
value = baseCollection.Count
Gets the number of items in the collection.
protected TCollection InnerCollection { get; }
value = baseCollection.InnerCollection
Gets the inner collection that stores the items.
public virtual bool IsReadOnly { get; }
value = baseCollection.IsReadOnly
Gets a value indicating whether the collection is read-only.
public virtual TItem Item { get; set; }
value = baseCollection.Item
baseCollection.Item = value
Gets or sets the item at the specified index.
- index
- The zero-based index of the item.
戻り値: The item at the specified index.
System#Collections#ICollection#IsSynchronized
Gets a value indicating whether the collection is synchronized (non-generic). Always returns false.
System#Collections#ICollection#SyncRoot
Gets the synchronization root object (non-generic). Returns the current instance.
System#Collections#IList#IsFixedSize
Gets a value indicating whether the collection has a fixed size (non-generic). Always returns false.
System#Collections#IList#IsReadOnly
Gets a value indicating whether the collection is read-only (non-generic).
System#Collections#IList#Item
Gets or sets the item at the specified index (non-generic).
- index
- The zero-based index of the item.
戻り値: The item at the specified index.
メソッド
public virtual void Add(TItem item)
baseCollection.Add(item)
Adds an item to the collection.
- item
- The item to add.
private void CheckIndex(int index)
baseCollection.CheckIndex(index)
Validates the specified index to ensure it is within the valid range.
- index
- The index to check.
public virtual bool Contains(TItem item)
result = baseCollection.Contains(item)
Determines whether the collection contains a specific item.
- item
- The item to locate.
戻り値: True if the item is found; otherwise, false.
public void CopyTo(TItem[] array, int index)
baseCollection.CopyTo(array, index)
Copies the elements of the collection to an array.
- array
- The destination array.
- index
- The zero-based index in the array at which copying begins.
public virtual IEnumerator<TItem> GetEnumerator()
result = baseCollection.GetEnumerator()
Returns an enumerator that iterates through the collection.
戻り値: An enumerator for the collection.
public abstract int IndexOf(TItem item)
result = baseCollection.IndexOf(item)
Returns the index of the specified item in the collection.
- item
- The item to locate.
戻り値: The zero-based index of the item, or -1 if not found.
public virtual void Insert(int index, TItem item)
baseCollection.Insert(index, item)
Inserts an item into the collection at the specified index.
- index
- The zero-based index at which to insert the item.
- item
- The item to insert.
private static bool IsCompatible(object value)
result = BaseCollection.IsCompatible(value)
Determines whether a value is compatible with the collection's item type.
- value
- The value to check.
戻り値: True if the value is compatible; otherwise, false.
protected virtual void OnAdd(TItem item)
baseCollection.OnAdd(item)
Adds an item to the inner collection.
- item
- The item to add.
protected virtual void OnAdded(TItem item)
baseCollection.OnAdded(item)
Invokes the Added event and notifies of a change after adding an item.
- item
- The added item.
protected virtual bool OnAdding(TItem item)
result = baseCollection.OnAdding(item)
Invokes the Adding event before adding an item.
- item
- The item to add.
戻り値: True if the addition should proceed; otherwise, false.
protected virtual void OnChanged()
baseCollection.OnChanged()
Invokes the Changed event to notify of a modification in the collection.
protected virtual void OnClear()
baseCollection.OnClear()
Removes all items from the inner collection.
protected virtual void OnCleared()
baseCollection.OnCleared()
Invokes the Cleared event and notifies of a change after clearing the collection.
protected virtual bool OnClearing()
result = baseCollection.OnClearing()
Invokes the Clearing event before clearing the collection.
戻り値: True if the clearing should proceed; otherwise, false.
protected abstract TItem OnGetItem(int index)
result = baseCollection.OnGetItem(index)
Retrieves an item at the specified index from the inner collection.
- index
- The zero-based index of the item to retrieve.
戻り値: The item at the specified index.
protected abstract void OnInsert(int index, TItem item)
baseCollection.OnInsert(index, item)
Inserts an item into the inner collection at the specified index.
- index
- The zero-based index at which to insert the item.
- item
- The item to insert.
protected virtual void OnInserted(int index, TItem item)
baseCollection.OnInserted(index, item)
Invokes the Inserted event and notifies of a change after inserting an item.
- index
- The zero-based index at which the item was inserted.
- item
- The inserted item.
protected virtual bool OnInserting(int index, TItem item)
result = baseCollection.OnInserting(index, item)
Invokes the Inserting event before inserting an item.
- index
- The zero-based index at which to insert the item.
- item
- The item to insert.
戻り値: True if the insertion should proceed; otherwise, false.
protected virtual bool OnRemove(TItem item)
result = baseCollection.OnRemove(item)
Removes an item from the inner collection.
- item
- The item to remove.
戻り値: True if the item was removed; otherwise, false.
protected abstract void OnRemoveAt(int index)
baseCollection.OnRemoveAt(index)
Removes an item from the inner collection at the specified index.
- index
- The zero-based index of the item to remove.
protected virtual void OnRemoved(TItem item)
baseCollection.OnRemoved(item)
Invokes the Removed event and notifies of a change after removing an item.
- item
- The removed item.
protected virtual void OnRemovedAt(int index)
baseCollection.OnRemovedAt(index)
Invokes the RemovedAt event and notifies of a change after removing an item at the specified index.
- index
- The zero-based index of the removed item.
protected virtual bool OnRemoving(TItem item)
result = baseCollection.OnRemoving(item)
Invokes the Removing event before removing an item.
- item
- The item to remove.
戻り値: True if the removal should proceed; otherwise, false.
protected virtual bool OnRemovingAt(int index)
result = baseCollection.OnRemovingAt(index)
Invokes the RemovingAt event before removing an item at the specified index.
- index
- The zero-based index of the item to remove.
戻り値: True if the removal should proceed; otherwise, false.
public virtual bool Remove(TItem item)
result = baseCollection.Remove(item)
Removes the specified item from the collection.
- item
- The item to remove.
戻り値: True if the item was removed; otherwise, false.
public virtual void RemoveAt(int index)
baseCollection.RemoveAt(index)
Removes the item at the specified index.
- index
- The zero-based index of the item to remove.
System#Collections#ICollection#CopyTo(Array, int)
Copies the elements of the collection to an array (non-generic).
- array
- The destination array.
- index
- The zero-based index in the array at which copying begins.
System#Collections#IEnumerable#GetEnumerator()
Returns an enumerator that iterates through the collection (non-generic version).
戻り値: An enumerator for the collection.
System#Collections#IList#Add(object)
Adds a value to the collection (non-generic).
- value
- The value to add.
戻り値: The new count of items in the collection.
System#Collections#IList#Clear()
Removes all items from the collection (non-generic).
System#Collections#IList#Contains(object)
Determines whether the collection contains a specific value (non-generic).
- value
- The value to locate.
戻り値: True if the value is found and compatible; otherwise, false.
System#Collections#IList#IndexOf(object)
Returns the index of a specific value in the collection (non-generic).
- value
- The value to locate.
戻り値: The zero-based index of the value, or -1 if not found or incompatible.
System#Collections#IList#Insert(int, object)
Inserts a value into the collection at the specified index (non-generic).
- index
- The zero-based index at which to insert the value.
- value
- The value to insert.
System#Collections#IList#Remove(object)
Removes a specific value from the collection (non-generic).
- value
- The value to remove.
System#Collections#IList#RemoveAt(int)
Removes the item at the specified index (non-generic).
- index
- The zero-based index of the item to remove.
イベント
public event Action<TItem> Added
baseCollection.Added += handler
Occurs after an item has been added to the collection.
public event Func<TItem, bool> Adding
baseCollection.Adding += handler
Occurs before an item is added to the collection.
public event Action Changed
baseCollection.Changed += handler
Occurs when the collection has been modified.
public event Action Cleared
baseCollection.Cleared += handler
Occurs after the collection has been cleared.
public event Func<bool> Clearing
baseCollection.Clearing += handler
Occurs before the collection is cleared.
public event Action<int, TItem> Inserted
baseCollection.Inserted += handler
Occurs after an item has been inserted at the specified index.
public event Func<int, TItem, bool> Inserting
baseCollection.Inserting += handler
Occurs before an item is inserted at the specified index.
public event Action<TItem> Removed
baseCollection.Removed += handler
Occurs after an item has been removed from the collection.
public event Action<int> RemovedAt
baseCollection.RemovedAt += handler
Occurs after an item has been removed at the specified index.
public event Func<TItem, bool> Removing
baseCollection.Removing += handler
Occurs before an item is removed from the collection.
public event Func<int, bool> RemovingAt
baseCollection.RemovingAt += handler
Occurs before an item is removed at the specified index.