BaseCollection

Ecng.Collections

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

构造函数

BaseCollection
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.

属性

CheckNullableItems
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.

Count
public virtual int Count { get; }
value = baseCollection.Count

Gets the number of items in the collection.

InnerCollection
protected TCollection InnerCollection { get; }
value = baseCollection.InnerCollection

Gets the inner collection that stores the items.

IsReadOnly
public virtual bool IsReadOnly { get; }
value = baseCollection.IsReadOnly

Gets a value indicating whether the collection is read-only.

Item
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.

方法

Add
public virtual void Add(TItem item)
baseCollection.Add(item)

Adds an item to the collection.

item
The item to add.
CheckIndex
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.
Clear
public virtual void Clear()
baseCollection.Clear()

Removes all items from the collection.

Contains
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.

CopyTo
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.
GetEnumerator
public virtual IEnumerator<TItem> GetEnumerator()
result = baseCollection.GetEnumerator()

Returns an enumerator that iterates through the collection.

返回值: An enumerator for the collection.

IndexOf
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.

Insert
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.
IsCompatible
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.

OnAdd
protected virtual void OnAdd(TItem item)
baseCollection.OnAdd(item)

Adds an item to the inner collection.

item
The item to add.
OnAdded
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.
OnAdding
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.

OnChanged
protected virtual void OnChanged()
baseCollection.OnChanged()

Invokes the Changed event to notify of a modification in the collection.

OnClear
protected virtual void OnClear()
baseCollection.OnClear()

Removes all items from the inner collection.

OnCleared
protected virtual void OnCleared()
baseCollection.OnCleared()

Invokes the Cleared event and notifies of a change after clearing the collection.

OnClearing
protected virtual bool OnClearing()
result = baseCollection.OnClearing()

Invokes the Clearing event before clearing the collection.

返回值: True if the clearing should proceed; otherwise, false.

OnGetItem
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.

OnInsert
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.
OnInserted
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.
OnInserting
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.

OnRemove
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.

OnRemoveAt
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.
OnRemoved
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.
OnRemovedAt
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.
OnRemoving
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.

OnRemovingAt
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.

Remove
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.

RemoveAt
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.

事件

Added
public event Action<TItem> Added
baseCollection.Added += handler

Occurs after an item has been added to the collection.

Adding
public event Func<TItem, bool> Adding
baseCollection.Adding += handler

Occurs before an item is added to the collection.

Changed
public event Action Changed
baseCollection.Changed += handler

Occurs when the collection has been modified.

Cleared
public event Action Cleared
baseCollection.Cleared += handler

Occurs after the collection has been cleared.

Clearing
public event Func<bool> Clearing
baseCollection.Clearing += handler

Occurs before the collection is cleared.

Inserted
public event Action<int, TItem> Inserted
baseCollection.Inserted += handler

Occurs after an item has been inserted at the specified index.

Inserting
public event Func<int, TItem, bool> Inserting
baseCollection.Inserting += handler

Occurs before an item is inserted at the specified index.

Removed
public event Action<TItem> Removed
baseCollection.Removed += handler

Occurs after an item has been removed from the collection.

RemovedAt
public event Action<int> RemovedAt
baseCollection.RemovedAt += handler

Occurs after an item has been removed at the specified index.

Removing
public event Func<TItem, bool> Removing
baseCollection.Removing += handler

Occurs before an item is removed from the collection.

RemovingAt
public event Func<int, bool> RemovingAt
baseCollection.RemovingAt += handler

Occurs before an item is removed at the specified index.