@@ -168,3 +168,39 @@ public void Dispose() { }
168168
169169 public T Current => default ( T ) ! ;
170170}
171+
172+ public class DelegateBasedCollection < T > : ICollection < T >
173+ {
174+ public Func < int > CountWorker { get ; set ; }
175+ public Func < bool > IsReadOnlyWorker { get ; set ; }
176+ public Action < T > AddWorker { get ; set ; }
177+ public Action ClearWorker { get ; set ; }
178+ public Func < T , bool > ContainsWorker { get ; set ; }
179+ public Func < T , bool > RemoveWorker { get ; set ; }
180+ public Action < T [ ] , int > CopyToWorker { get ; set ; }
181+ public Func < IEnumerator < T > > GetEnumeratorWorker { get ; set ; }
182+ public Func < IEnumerator > NonGenericGetEnumeratorWorker { get ; set ; }
183+
184+ public DelegateBasedCollection ( )
185+ {
186+ CountWorker = ( ) => 0 ;
187+ IsReadOnlyWorker = ( ) => false ;
188+ AddWorker = item => { } ;
189+ ClearWorker = ( ) => { } ;
190+ ContainsWorker = item => false ;
191+ RemoveWorker = item => false ;
192+ CopyToWorker = ( array , arrayIndex ) => { } ;
193+ GetEnumeratorWorker = ( ) => Enumerable . Empty < T > ( ) . GetEnumerator ( ) ;
194+ NonGenericGetEnumeratorWorker = ( ) => GetEnumeratorWorker ( ) ;
195+ }
196+
197+ public int Count => CountWorker ( ) ;
198+ public bool IsReadOnly => IsReadOnlyWorker ( ) ;
199+ public void Add ( T item ) => AddWorker ( item ) ;
200+ public void Clear ( ) => ClearWorker ( ) ;
201+ public bool Contains ( T item ) => ContainsWorker ( item ) ;
202+ public bool Remove ( T item ) => RemoveWorker ( item ) ;
203+ public void CopyTo ( T [ ] array , int arrayIndex ) => CopyToWorker ( array , arrayIndex ) ;
204+ public IEnumerator < T > GetEnumerator ( ) => GetEnumeratorWorker ( ) ;
205+ IEnumerator IEnumerable . GetEnumerator ( ) => NonGenericGetEnumeratorWorker ( ) ;
206+ }
0 commit comments