© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
12 replies
Rotor

Implementing IEnumerable<T>

Hi all!

I'm trying to simplify a complex return type that I have to repeat in a lot of places

Result<IEnumerable<Result<TRow, Faults<TDataFault>>>, Faults<TMetadatFault>>
Result<IEnumerable<Result<TRow, Faults<TDataFault>>>, Faults<TMetadatFault>>


Although I'm pleased with how the type allows me to easily package and aggregate errors that I encounter without having to throw and catch them, the length of the type does no favours to the code's readability.

I sought to start to simplify the type a bit by contracting
IEnumerable<Result<TRow, Faults<TDataFault>>>
IEnumerable<Result<TRow, Faults<TDataFault>>>

down to
IRowSeq<TRow, TDataFault>
IRowSeq<TRow, TDataFault>


Which I tried to implement using the following code
internal interface IRowSeq<TRow, TDataFault>
    : IEnumerable<Result<TRow, Faults<TDataFault>>>
    where TRow : IRowType
    where TDataFault : Enum
{

    public new IEnumerator<Result<TRow, Faults<TDataFault>>> GetEnumerator();

    IEnumerator IEnumerable.GetEnumerator() =>
        this.GetEnumerator();
}
internal interface IRowSeq<TRow, TDataFault>
    : IEnumerable<Result<TRow, Faults<TDataFault>>>
    where TRow : IRowType
    where TDataFault : Enum
{

    public new IEnumerator<Result<TRow, Faults<TDataFault>>> GetEnumerator();

    IEnumerator IEnumerable.GetEnumerator() =>
        this.GetEnumerator();
}


Although the code compiles, once I started to update the code I use to generate an
IEnumerable
IEnumerable

    private static IRowSeq<TRow, TDataFault> GetRows(ExcelData excelData)
    {
        ulong rowNumber = 1;
        
        foreach (var row in excelData.Rows.Skip(1)) // By this point in the code the header has been confirmed
        {
            yield return ParseAndValidateCells(excelData, row, rowNumber);

            rowNumber++;
        }
    }
    private static IRowSeq<TRow, TDataFault> GetRows(ExcelData excelData)
    {
        ulong rowNumber = 1;
        
        foreach (var row in excelData.Rows.Skip(1)) // By this point in the code the header has been confirmed
        {
            yield return ParseAndValidateCells(excelData, row, rowNumber);

            rowNumber++;
        }
    }


Then I hit
csharp(CS1624)
csharp(CS1624)
-
the body of (method) cannot be an iterator block because 'IRowSeq<TRow, TDataFault>' is not an iterator interface type
the body of (method) cannot be an iterator block because 'IRowSeq<TRow, TDataFault>' is not an iterator interface type


Perhaps I'm looking at this problem from the wrong angle. Could somebody please set me right?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ What is IEnumerable<out T> ?
C#CC# / help
3y ago
✅ Can my Equals(IEnumerable<T>? x, IEnumerable<T>? y) be made much simpler?
C#CC# / help
3y ago
IEnumerable<T> (or List<T>, or T[]) to IEnumerable (non-generic, ie. no type param)?
C#CC# / help
2y ago
IEnumerable<Author>
C#CC# / help
3mo ago