protected override IEnumerable <IRow> Produce() { var inputRows = InputGenerator.Invoke(this); if (ColumnConfiguration != null) { var initialValues = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase); if (CopyOnlySpecifiedColumns) { foreach (var row in inputRows) { if (Context.CancellationTokenSource.IsCancellationRequested) { yield break; } foreach (var config in ColumnConfiguration) { var value = HandleConverter(row[config.SourceColumn], config); initialValues[config.RowColumn ?? config.SourceColumn] = value; } var newRow = Context.CreateRow(this, initialValues); newRow.Tag = row.Tag; yield return(newRow); initialValues.Clear(); } } else { var columnConfig = ColumnConfiguration.ToDictionary(x => x.SourceColumn.ToUpperInvariant()); foreach (var row in inputRows) { if (Context.CancellationTokenSource.IsCancellationRequested) { yield break; } foreach (var config in ColumnConfiguration) { var value = HandleConverter(row[config.SourceColumn], config); initialValues[config.RowColumn ?? config.SourceColumn] = value; } foreach (var kvp in row.Values) { if (!columnConfig.ContainsKey(kvp.Key.ToUpperInvariant())) { if (DefaultColumnConfiguration != null) { var value = HandleConverter(kvp.Value, DefaultColumnConfiguration); initialValues[kvp.Key] = value; } else { initialValues[kvp.Key] = kvp.Value; } } } var newRow = Context.CreateRow(this, initialValues); newRow.Tag = row.Tag; yield return(newRow); initialValues.Clear(); } } } else { foreach (var row in inputRows) { if (Context.CancellationTokenSource.IsCancellationRequested) { yield break; } yield return(Context.CreateRow(this, row)); } } }
protected override IEnumerable <IRow> Produce() { var inputRows = InputGenerator.Invoke(this); if (Columns != null) { var initialValues = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase); if (CopyOnlySpecifiedColumns) { foreach (var inputRow in inputRows) { if (Context.IsTerminating) { yield break; } foreach (var columnKvp in Columns) { var value = columnKvp.Value.Process(this, inputRow[columnKvp.Value.SourceColumn ?? columnKvp.Key]); initialValues[columnKvp.Key] = value; } var newRow = Context.CreateRow(this, initialValues); newRow.Tag = inputRow.Tag; yield return(newRow); initialValues.Clear(); } } else { var columnMap = Columns != null ? new Dictionary <string, ReaderColumn>(Columns, StringComparer.InvariantCultureIgnoreCase) : null; foreach (var inputRow in inputRows) { if (Context.IsTerminating) { yield break; } foreach (var columnKvp in Columns) { var value = columnKvp.Value.Process(this, inputRow[columnKvp.Value.SourceColumn ?? columnKvp.Key]); initialValues[columnKvp.Key] = value; } foreach (var valueKvp in inputRow.Values) { if (!columnMap.ContainsKey(valueKvp.Key.ToUpperInvariant())) { if (DefaultColumns != null) { var value = DefaultColumns.Process(this, valueKvp.Value); initialValues[valueKvp.Key] = value; } else { initialValues[valueKvp.Key] = valueKvp.Value; } } } var newRow = Context.CreateRow(this, initialValues); newRow.Tag = inputRow.Tag; yield return(newRow); initialValues.Clear(); } } } else { foreach (var row in inputRows) { if (Context.IsTerminating) { yield break; } yield return(Context.CreateRow(this, row)); } } }