Create an interface that derives from IEnumerable

I have a couple of classes, all of which are related to IQueryResult. I need each of these classes to be iterable in a foreach loop. Unfortunately, the foreach loop cannot see the GetEnumerator method. I managed to use it in foreach using the dynamic keyword available in .NET 4.0, but then IQueryResult does not need to be inferred from IEnumerable.

public interface IQueryResult : IEnumerable<IQueryResult>
{
}

How would you make it more elegant?

Regards PC

+3
source share
2 answers

Is it IQueryResult really IEnumerable<IQueryResult> ? I could expect, for example, that (for a single grid):

public interface IQueryResult<T> : IEnumerable<T> { /* */ }

or if you are trying to imagine multiple grids:

public interface IQueryResult<T> : IEnumerable<IEnumerable<T>> { /* */ }

:

public interface IQueryResult<T> {
    IEnumerable<IEnumerable<T>> GetGrids(); // or something
}

, IEnumerable[<T>] foreach, LINQ ..

+1

. dont ineterfaces.

. expilcit, IEnumarable ,

-1

Source: https://habr.com/ru/post/1726166/


All Articles