public static TableLine FromStringCollection(IEnumerable <string> collection) { var tableLine = new TableLine(); var props = tableLine.GetType().GetProperties(); foreach (var zip in collection.Zip(props, (s, p) => new { s, p })) { zip.p.SetValue(tableLine, zip.s); } return(tableLine); }
private void BeginDeviceBuildingFrom(TableLine line) { try { device = new Device() { Name = line.Name.Trim(), Count = int.Parse(line.CountString.Trim()), Supplier = line.Supplier.Trim() }; } catch (FormatException ex) { throw new FormatException($"Неверный формат у строки {line}.", ex); } }
private static IEnumerable<TableLine> GetLines(string documentPath) { using (var document = DocX.Load(File.OpenRead(documentPath))) { var detector = new HeaderDetector(); var bidTables = document.Tables.Where(t => IsBidTable(t, detector)); foreach (var table in bidTables) { IEnumerable<Row> rowsWithoutHeader = table.Rows.Skip(1); foreach (var row in rowsWithoutHeader) { yield return TableLine.FromStringCollection(row.GetValues()); } } } }
private void Append(TableLine line) { device.Name += line.Name; device.Supplier += line.Supplier; }