public DataReaderWrapper(IDataReader reader, DataReaderWrapperParameters parameters, CancellationToken cancelToken) { _Reader = reader ?? throw new ArgumentNullException(nameof(reader)); _CancelToken = cancelToken; InitializeColumnMap(parameters); _CloseAction = parameters?.CloseAction; _IgnoreReaderErrors = parameters?.IgnoreReaderErrors ?? false; }
protected void InitializeColumnMap(DataReaderWrapperParameters parameters) { var columns = new List <string>(); if (parameters?.Columns != null) { columns.AddRange(parameters.Columns); } if (columns.Count <= 0) { for (int i = 0; i < _Reader.FieldCount; i++) { columns.Add(_Reader.GetName(i)); } } if ((parameters.SkipColumns?.Length ?? 0) > 0) { var dictSkip = new StringNoCaseDictionary <int>(); foreach (string skipColumn in parameters.SkipColumns) { if (!dictSkip.ContainsKey(skipColumn)) { dictSkip.Add(skipColumn, 1); } else { dictSkip[skipColumn]++; } } for (int i = columns.Count - 1; i >= 0; i--) { if (dictSkip.ContainsKey(columns[i])) { columns.RemoveAt(i); } } } for (int i = 0; i < columns.Count; i++) { string columnName = columns[i]; int ordinal = _Reader.GetOrdinal(columnName); if (ordinal < 0) { throw new Exception($"Cannot find column '{columnName}'"); } ColumnMap.Add(i, ordinal); ColumnMapReverse.Add(ordinal, i); } }
public DataReaderWrapper(IDataReader reader, DataReaderWrapperParameters parameters) : this(reader, parameters, CancellationToken.None) { }