You need to pass through any enumerator-related calls made to your collection to your underlying list, as follows:
public class MyTest<T> : ICollection<T>
{
private List<T> myUnderlyingList = new List<T>();
public IEnumerator<T> GetEnumerator()
{
return myUnderlyingList.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
.... etc.
Then LINQ will simply be 'seeing' the underlying List when it performs its operations.
The other thing to make sure is that your underlying List<T>
is populated correctly with valid data before you run any LINQ methods on it.