private static T[] Parse <T>(IParser2D <T> parser, string?input, int y) { if (string.IsNullOrWhiteSpace(input)) { return(Array.Empty <T>()); } return(parser.Parse(y, input)); }
public async static Task <IEnumerable <T> > GetInput <T>(string resourceNamePath, IParser2D <T> parser) { List <string> inputRows = new List <string>(); string assembly = resourceNamePath.Split('.')[0]; using (Stream? stream = Assembly.LoadFrom(assembly).GetManifestResourceStream(resourceNamePath)) using (StreamReader reader = new StreamReader(stream !)) { string?nextLine = await reader.ReadLineAsync(); if (!string.IsNullOrWhiteSpace(nextLine)) { inputRows.Add(nextLine); } while (!string.IsNullOrWhiteSpace(nextLine)) { nextLine = await reader.ReadLineAsync(); if (!string.IsNullOrWhiteSpace(nextLine)) { inputRows.Add(nextLine); } } } inputRows.Reverse(); return(inputRows.Select((input, y) => parser.Parse(y, input)).SelectMany(item => item)); }