public bool Equals(NarrowRow <T> other) { if (other == null) { return(false); } if (Column == null) { return(other.Column == null); } return(this.Column.Equals(other.Column)); }
private static Action <TextWriter> MakeRunGeneric <T>(string rowSet, string library) { const int NUM_SHALLOW = 10; const int NUM_DEEP = 10_000; IEnumerable <NarrowRow <T> > rows; var r = MakeRandom(); switch (rowSet) { case "ShallowRows": rows = Enumerable.Range(0, NUM_SHALLOW).Select(_ => NarrowRow <T> .Create(r)).ToArray(); break; case "DeepRows": rows = Enumerable.Range(0, NUM_DEEP).Select(_ => NarrowRow <T> .Create(r)).ToArray(); break; default: throw new Exception(); } Action <IEnumerable <NarrowRow <T> >, TextWriter> writeDel; switch (library) { case nameof(Cesil): { var opts = Options.CreateBuilder(Options.Default).WithWriteTrailingRowEnding(WriteTrailingRowEnding.Always).ToOptions(); var config = Configuration.For <NarrowRow <T> >(opts); writeDel = MakeWriteWithCesilDel(config); } break; case nameof(CsvHelper): { var config = new CsvHelper.Configuration.CsvConfiguration(CultureInfo.InvariantCulture); config.RegisterClassMap <NarrowRowMapping <T> >(); writeDel = MakeWriteWithCsvHelper(config); } break; default: throw new Exception(); } return(writer => writeDel(rows, writer));
private static string MakeCsv <T>(string rowSet) { const int NUM_SHALLOW = 10; const int NUM_DEEP = 10_000; string csv; { IEnumerable <NarrowRow <T> > rows; var r = new Random(2020_04_20); switch (rowSet) { case "ShallowRows": rows = Enumerable.Range(0, NUM_SHALLOW).Select(_ => NarrowRow <T> .Create(r)).ToArray(); break; case "DeepRows": rows = Enumerable.Range(0, NUM_DEEP).Select(_ => NarrowRow <T> .Create(r)).ToArray(); break; default: throw new Exception(); } var opts = Options.CreateBuilder(Options.Default).WithWriteTrailingRowEnding(WriteTrailingRowEnding.Always).ToOptions(); var config = Configuration.For <NarrowRow <T> >(opts); using (var str = new StringWriter()) { using (var writer = config.CreateWriter(str)) { writer.WriteAll(rows); } csv = str.ToString(); } } return(csv); }
private static Func <IEnumerable <object> > MakeRunGeneric <T>(string rowSet, string lib) { const int NUM_SHALLOW = 10; const int NUM_DEEP = 10_000; string csv; { IEnumerable <NarrowRow <T> > rows; var r = MakeRandom(); switch (rowSet) { case "ShallowRows": rows = Enumerable.Range(0, NUM_SHALLOW).Select(_ => NarrowRow <T> .Create(r)).ToArray(); break; case "DeepRows": rows = Enumerable.Range(0, NUM_DEEP).Select(_ => NarrowRow <T> .Create(r)).ToArray(); break; default: throw new Exception(); } var opts = Options.CreateBuilder(Options.Default).WithWriteTrailingRowEnding(WriteTrailingRowEnding.Always).ToOptions(); var config = Configuration.For <NarrowRow <T> >(opts); using (var str = new StringWriter()) { using (var writer = config.CreateWriter(str)) { writer.WriteAll(rows); } csv = str.ToString(); } } switch (lib) { case nameof(Cesil): { var opts = Options.CreateBuilder(Options.Default).WithWriteTrailingRowEnding(WriteTrailingRowEnding.Always).ToOptions(); var config = Configuration.For <NarrowRow <T> >(opts); return (() => { var ret = new List <object>(); using (var str = new StringReader(csv)) using (var csv = config.CreateReader(str)) { var rows = csv.EnumerateAll(); foreach (var row in rows) { ret.Add(row); } return ret; } }); } case nameof(CsvHelper): { var config = new CsvHelper.Configuration.CsvConfiguration(CultureInfo.InvariantCulture); config.RegisterClassMap <NarrowRowMapping <T> >(); config.IgnoreBlankLines = false; return (() => { var ret = new List <object>(); using (var str = new StringReader(csv)) using (var csv = new CsvHelper.CsvReader(str, config)) { var rows = csv.GetRecords <NarrowRow <T> >(); foreach (var row in rows) { ret.Add(row); } return ret; } }); } default: throw new Exception(); }