Enhanced C#
Loyc library documentation
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events Pages
Properties | Public Member Functions | List of all members
Loyc.Collections.Impl.ListWrapper< T, TList > Class Template Reference

A simple base class that to helps you implement a "smart" collection. By default, all it does is forward every method to the underlying collection (including GetHashCode, Equals and ToString). You can change its behavior by overriding methods. More...


Source file:
Inheritance diagram for Loyc.Collections.Impl.ListWrapper< T, TList >:
Loyc.Collections.Impl.CollectionWrapper< T, TCollection > Loyc.Collections.IListAndListSource< T > Loyc.WrapperBase< T > Loyc.Collections.IListAndReadOnly< T > Loyc.Collections.IListSource< out T > Loyc.Collections.ICollectionAndSource< T > Loyc.Collections.ICollectionAndReadOnly< T > Loyc.Collections.ICollectionSource< T > Loyc.Collections.IIndexed< in K, out V > Loyc.Collections.ITryGet< in K, out V > Loyc.Collections.ISource< out T > Loyc.Collections.ICollectionAndReadOnly< T > Loyc.Collections.Impl.ListWithChangeEvents< T, TList > Loyc.Collections.ListWithChangeEvents< T >

Remarks

A simple base class that to helps you implement a "smart" collection. By default, all it does is forward every method to the underlying collection (including GetHashCode, Equals and ToString). You can change its behavior by overriding methods.

This could be used, for example, to help you implement a collection that needs to take some kind of action whenever the collection is modified.

Type Constraints
TList :IList<T> 

Properties

virtual T this[int index] [get, set]
 
- Properties inherited from Loyc.Collections.ISource< out T >
new int Count [get]
 Gets the number of items in the collection. More...
 
- Properties inherited from Loyc.Collections.ICount
int Count [get]
 Gets the number of items in the collection. More...
 
- Properties inherited from Loyc.Collections.IIsEmpty
bool IsEmpty [get]
 
- Properties inherited from Loyc.Collections.IIndexed< in K, out V >
this[K key] [get]
 Gets the value associated with the specified key. More...
 

Public Member Functions

 ListWrapper (TList wrappedObject)
 
virtual void Insert (int index, T item)
 
virtual void RemoveAt (int index)
 
virtual int IndexOf (T item)
 
virtual IListSource< T > Slice (int start, int count=int.MaxValue)
 Returns a sub-range of this list. More...
 
virtual T TryGet (int index, out bool fail)
 
- Public Member Functions inherited from Loyc.Collections.Impl.CollectionWrapper< T, TCollection >
 CollectionWrapper (TCollection collection)
 
virtual void Add (T item)
 
virtual void Clear ()
 
virtual bool Remove (T item)
 
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...
 
- Public Member Functions inherited from Loyc.Collections.ITryGet< in K, out V >
TryGet (K key, out bool fail)
 Gets the item for the specified key or index, and does not throw an exception on failure. More...
 
- Public Member Functions inherited from Loyc.Collections.ICollectionSource< T >
void CopyTo (T[] array, int arrayIndex)
 Copies the elements of the collection to an Array, starting at a particular array index. More...
 
- Public Member Functions inherited from Loyc.Collections.IContains< in T >
bool Contains (T item)
 Returns true if and only if the collection contains the specified item. More...
 

Additional Inherited Members

- Public fields inherited from Loyc.Collections.Impl.CollectionWrapper< T, TCollection >
bool IsEmpty => Count == 0
 
virtual int Count => _obj.Count
 
virtual bool IsReadOnly => _obj.IsReadOnly
 
- 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 IListSource<T> Loyc.Collections.Impl.ListWrapper< T, TList >.Slice ( int  start,
int  count = int.MaxValue 
)
virtual

Returns a sub-range of this list.

Parameters
startThe new range will start at this index in the current list (this location will be index [0] in the new range).
countThe desired number of elements in the new range, or int.MaxValue to get all elements until the end of the list.
Returns
Returns a sub-range of this range.
Exceptions
ArgumentExceptionThe start index was below zero.

The (start, count) range is allowed to be invalid, as long as start is zero or above.

  • If count is below zero, or if start is above the original Count, the Count of the new slice is set to zero.
  • if (start + count) is above the original Count, the Count of the new slice is reduced to this.Count - start. Implementation note: do not compute (start + count) because it may overflow. Instead, test whether (count > this.Count - start).

Most collections should use the following implementation:

IListSource<T> IListSource<T>.Slice(int start, int count) { return Slice(start, count); }
public Slice_<T> Slice(int start, int count) { return new Slice_<T>(this, start, count); }

Implements Loyc.Collections.IListSource< out T >.