private void HandleHeaders() { var options = Configuration.Options; if (options.ReadHeader == ReadHeader.Never) { // can just use the discovered copy from source ReadHeaders = ReadHeader.Never; ColumnCount = Configuration.DeserializeColumns.Length; TryMakeStateMachine(); return; } // should always have been initialized by now var rowEndings = Utils.NonNullValue(RowEndings); using ( var headerReader = new HeadersReader <T>( StateMachine, Configuration, SharedCharacterLookup, Inner, Buffer, rowEndings ) ) { var headers = headerReader.Read(); HandleHeadersReaderResult(headers); } }
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(); }
private void HandleHeaders() { if (Configuration.ReadHeader == Cesil.ReadHeaders.Never) { // can just use the discovered copy from source ReadHeaders = Cesil.ReadHeaders.Never; TryMakeStateMachine(); Columns = Configuration.DeserializeColumns; return; } var headerConfig = new ConcreteBoundConfiguration <T>( Configuration.NewCons, Configuration.DeserializeColumns, Array.Empty <Column>(), Array.Empty <bool>(), Configuration.ValueSeparator, Configuration.EscapedValueStartAndStop, Configuration.EscapeValueEscapeChar, RowEndings.Value, Configuration.ReadHeader, Configuration.WriteHeader, Configuration.WriteTrailingNewLine, Configuration.MemoryPool, Configuration.CommentChar, null, Configuration.ReadBufferSizeHint ); using ( var headerReader = new HeadersReader <T>( headerConfig, SharedCharacterLookup, Inner, Buffer ) ) { var headers = headerReader.Read(); HandleHeadersReaderResult(headers); } }
private void HandleHeaders() { ReadHeaders = Configuration.ReadHeader; TryMakeStateMachine(); var allowColumnsByName = Configuration.ReadHeader == Cesil.ReadHeaders.Always; using (var reader = new HeadersReader <object>(Configuration, SharedCharacterLookup, Inner, Buffer)) { var res = reader.Read(); var foundHeaders = res.Headers.Count; if (foundHeaders == 0) { Throw.InvalidOperationException("Expected a header row, but found no headers"); } Columns = new Column[foundHeaders]; if (allowColumnsByName) { ColumnNames = new string[foundHeaders]; } using (var e = res.Headers) { var ix = 0; while (e.MoveNext()) { var name = allowColumnsByName ? new string(e.Current.Span) : null; if (name != null) { ColumnNames[ix] = name; } var col = new Column(name, Column.MakeDynamicSetter(name, ix), null, false); Columns[ix] = col; ix++; } } Buffer.PushBackFromOutsideBuffer(res.PushBack); } }