rotor_
rotor_
CC#
Created by rotor_ on 2/23/2023 in #help
❔ Loading static data without Visual Studio
I've got a number of static files (json, csv etc) that I need to make visible to my solution. On Visual Studio I'd add them as resources and the IDE would take care of everything for me. It doesn't look like that's an option with VSC, though. What's the idiomatic approach that I should use when developing using Visual Studio Code?
26 replies
CC#
Created by rotor_ on 2/15/2023 in #help
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>> 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>>> down to 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
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) - 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?
13 replies