Enhanced C#
Loyc library documentation
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events Pages
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, TCollection > Loyc.Collections.ICollectionWithChangeEvents< T > Loyc.WrapperBase< T > Loyc.Collections.INotifyListChanging< T, TCollection > Loyc.Collections.INotifyListChanged< T, TCollection > Loyc.Collections.CollectionWithChangeEvents< 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
 
- Public fields inherited from Loyc.Collections.Impl.CollectionWrapper< T, TCollection >
bool IsEmpty => Count == 0
 
virtual int Count => _obj.Count
 
virtual bool IsReadOnly => _obj.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, TCollection >
 CollectionWrapper (TCollection collection)
 
virtual bool Contains (T item)
 
virtual void CopyTo (T[] array, int arrayIndex)
 
virtual IEnumerator< T > GetEnumerator ()
 
- Public Member Functions inherited from Loyc.WrapperBase< T >
override bool Equals (object?obj)
 Returns true iff the parameter 'obj' is a wrapper around an object that is equal to the object that this object wraps. More...
 
override int GetHashCode ()
 Returns the hashcode of the wrapped object. More...
 
override string ToString ()
 Returns ToString() of the wrapped object. More...
 

Events

CollectionWithChangeEvents(TColl
wrappedObject) virtual
ListChangingHandler< T,
ICollection< T > > 
ListChanging
 
virtual ListChangingHandler< T,
ICollection< T > > 
ListChanged
 
- Events inherited from Loyc.Collections.INotifyListChanging< T, TCollection >
ListChangingHandler< T,
TCollection > 
ListChanging
 Occurs when the collection associated with this interface is about to change. More...
 
- Events inherited from Loyc.Collections.INotifyListChanged< T, TCollection >
ListChangingHandler< T,
TCollection > 
ListChanged
 Occurs when the collection associated with this interface has changed. More...
 

Additional Inherited Members

- Protected Member Functions inherited from Loyc.WrapperBase< T >
 WrapperBase (T wrappedObject)
 
- Protected fields inherited from Loyc.Collections.Impl.CollectionWrapper< T, TCollection >
TCollection Collection => _obj
 
- Protected fields inherited from Loyc.WrapperBase< T >
_obj
 
- Protected static fields inherited from Loyc.WrapperBase< T >
static readonly
EqualityComparer< T > 
TComp = EqualityComparer<T>.Default
 

Member Function Documentation

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.