public T this[int key] { get { return(_Rows.GetOrAdd(key, k => { if (!_Source.ContainsRow(k)) { throw new KeyNotFoundException(); } return CreateRow(_Source[key]); })); } }
private IEnumerable <DefinitionUpdater> MatchRows() { var defUpdaters = _PreviousDefinition.DataDefinitions.Select(_ => new DefinitionUpdater(_PreviousDefinition, _)).ToArray(); foreach (IRow prevRow in _PreviousSheet) { var prevRowFields = _PreviousSheet.Header.Columns.OrderBy(_ => _.Index).Select(_ => prevRow[_.Index]).ToArray(); if (!_UpdatedSheet.ContainsRow(prevRow.Key)) { continue; } var updatedRow = _UpdatedSheet[prevRow.Key]; var updatedRowFields = _UpdatedSheet.Header.Columns.OrderBy(_ => _.Index).Select(_ => updatedRow[_.Index]).ToArray(); foreach (var def in defUpdaters) { def.MatchRow(prevRowFields, updatedRowFields); } } return(defUpdaters); }
public IRelationalRow FindReference(int key) { // Optimization for unlikely references. if (key <= 0) { return(null); } foreach (SheetDefinition sheetDef in Definition.SheetDefinitions.Where(d => d.IsGenericReferenceTarget)) { IRelationalSheet sheet = GetSheet(sheetDef.Name); if (!sheet.Header.DataFileRanges.Any(r => r.Contains(key))) { continue; } if (!sheet.ContainsRow(key)) { continue; } return(sheet[key]); } return(null); }
public T this[int key] { get { if (_Rows.TryGetValue(key, out var row)) { return(row); } if (!_Source.ContainsRow(key)) { throw new KeyNotFoundException(); } var sourceRow = _Source[key]; row = CreateRow(sourceRow); _Rows.Add(key, row); return(row); } }
private IEnumerable <DefinitionUpdater> MatchRows() { var defUpdaters = _PreviousDefinition.DataDefinitions.Select(_ => new DefinitionUpdater(_PreviousDefinition, _)).ToArray(); // Record a list of compatible indexes by previous sheet column. // These are the only columns to be tested. var comparers = _PreviousSheet.Header.Columns .Select(c => ColumnComparer.Create(c, _UpdatedSheet.Header.Columns)) .ToArray(); if (_PreviousSheet.Header.Variant == 2) { return(MatchVariant2Rows(defUpdaters, comparers)); } foreach (IRow prevRow in _PreviousSheet) { if (!_UpdatedSheet.ContainsRow(prevRow.Key)) { continue; } var prevRowFields = _PreviousSheet.Header.Columns.OrderBy(_ => _.Index).Select(_ => prevRow[_.Index]).ToArray(); var updatedRow = _UpdatedSheet[prevRow.Key]; var updatedRowFields = _UpdatedSheet.Header.Columns.OrderBy(_ => _.Index).Select(_ => updatedRow[_.Index]).ToArray(); foreach (var def in defUpdaters) { def.MatchRow(prevRowFields, updatedRowFields, comparers); } } return(defUpdaters); }
public IRow GetRow(IRelationalSheet sheet, int key) { return(!sheet.ContainsRow(key) ? null : sheet[key]); }