excel-mapper icon indicating copy to clipboard operation
excel-mapper copied to clipboard

.Any() method on IEnumerable from ReadRows improperly moves the pointer to the next item in the object

Open motoyugota opened this issue 1 year ago • 0 comments

ExcelSheet sheet = importer.ReadSheet();
var items = sheet.ReadRows<MyItem>();

if (!items.Any())
{
    //Handle empty set
}

var list = items.ToList(); // This is now missing the first item from the sheet.

Following the standards for IEnumerable in C#, .Any() is not supposed to modify the IEnumerable in any way, including changing the pointer location in the collection, so you should still be able to retrieve the entire list.

It looks like .ToList() also has the same problem, so if you do .ToList() followed by .Any(), it now returns false instead of true. ToList is also not supposed to modify the IEnumerable.

motoyugota avatar Mar 11 '23 22:03 motoyugota