internal DynamicReader(IReaderAdapter reader, DynamicBoundConfiguration config, object?context) : base(reader, config, context, new DynamicRowConstructor(), config.Options.ExtraColumnTreatment) { NameLookupReferenceCount = 0; NameLookup = NameLookup.Empty; DelegateCache = new ConcurrentDictionary <object, Delegate>(); }
private void HandleHeaders() { var options = Configuration.Options; ReadHeaders = options.ReadHeader; var allowColumnsByName = options.ReadHeader == ReadHeader.Always; using (var reader = new HeadersReader <object>(StateMachine, Configuration, SharedCharacterLookup, Inner, Buffer, Utils.NonNullValue(RowEndings))) { var(headers, isHeader, pushBack) = reader.Read(); ColumnCount = headers.Count; if (ColumnCount == 0) { // rare, but possible if the file is empty or all comments or something like that ColumnNames.Value = Array.Empty <string>(); } else { string[] columnNamesValue = Array.Empty <string>(); if (allowColumnsByName) { columnNamesValue = new string[ColumnCount]; ColumnNames.Value = columnNamesValue; using (var e = headers) { var ix = 0; while (e.MoveNext()) { var name = allowColumnsByName ? new string(e.Current.Span) : null; if (name != null) { columnNamesValue[ix] = name; } ix++; } } Interlocked.Increment(ref NameLookupReferenceCount); NameLookup = NameLookup.Create(columnNamesValue, Configuration.MemoryPool); } RowBuilder.SetColumnOrder(Configuration.Options, headers); } Buffer.PushBackFromOutsideBuffer(pushBack); } TryMakeStateMachine(); }