Enhanced C#
Language of your choice: library documentation
Public fields | Public Member Functions | Events | List of all members
Loyc.Collections.Impl.CollectionWithChangeEvents< T, TColl > Class Template Reference

A collection wrapper that provides ListChanging and ListChanged events. You can also implement custom behavior by overriding its methods. More...


Source file:
Inheritance diagram for Loyc.Collections.Impl.CollectionWithChangeEvents< T, TColl >:
Loyc.Collections.Impl.CollectionWrapper< T, TColl > Loyc.Collections.ICollectionWithChangeEvents< T >

Remarks

A collection wrapper that provides ListChanging and ListChanged events. You can also implement custom behavior by overriding its methods.

This class is designed to support both sets and other collection types. If the underlying collection implements ISet<T>, the Add method avoids firing change notification events if the requested item is already in the set. Regardless of whether the collection is a set, the Remove method also avoids firing any notifications when the requested item is not in the collection.

Template Parameters
TType of each list item
TCollType of the underlying collection
Type Constraints
TColl :ICollection<T> 

Public fields

ISet< T > _asSet
 
bool IsEmpty => Count == 0
 
- Public fields inherited from Loyc.Collections.Impl.CollectionWrapper< T, TColl >
virtual int Count
 
virtual bool IsReadOnly
 

Public Member Functions

override void Add (T item)
 
virtual bool TryAdd (T item)
 Synonym for Add(). If the collection implements ISet{T}, this method returns false if the item is already present in the set; otherwise it always returns true. More...
 
override void Clear ()
 
override bool Remove (T item)
 
- Public Member Functions inherited from Loyc.Collections.Impl.CollectionWrapper< T, TColl >
 CollectionWrapper (TCollection collection)
 
virtual bool Contains (T item)
 
virtual void CopyTo (T[] array, int arrayIndex)
 
virtual IEnumerator< T > GetEnumerator ()
 

Events

CollectionWithChangeEvents(TColl wrappedObject) virtual ListChangingHandler< T, ICollection< T > > ListChanging
 
virtual ListChangingHandler< T, ICollection< T > > ListChanged
 

Additional Inherited Members

- Protected fields inherited from Loyc.Collections.Impl.CollectionWrapper< T, TColl >
TCollection Collection
 

Member Function Documentation

◆ TryAdd()

virtual bool Loyc.Collections.Impl.CollectionWithChangeEvents< T, TColl >.TryAdd ( item)
inlinevirtual

Synonym for Add(). If the collection implements ISet{T}, this method returns false if the item is already present in the set; otherwise it always returns true.

Returns
True if the item was added, false if the collection is a set and the item was already in the set.