/// <summary> /// Attempts to read the next record from the stream. /// </summary> /// <returns>True if the next record was read or false if all records have been read.</returns> public bool Read() { if (isDisposed) { throw new ObjectDisposedException("FixedLengthParser"); } if (hasError) { throw new InvalidOperationException(Resources.ReadingWithErrors); } if (reader.EndOfStream) { endOfFile = true; values = null; return(false); } string[] rawValues = readNextRecord(); recordCount += 1; if (schema == null) { values = rawValues; } else if (rawValues.Length != schema.ColumnDefinitions.Count) { hasError = true; throw new FlatFileException(recordCount); } else { values = schema.ParseValues(rawValues); } return(true); }
/// <summary> /// Attempts to read the next record from the stream. /// </summary> /// <returns>True if the next record was read or false if all records have been read.</returns> public bool Read() { if (hasError) { throw new InvalidOperationException(SharedResources.ReadingWithErrors); } if (parser.EndOfStream) { endOfFile = true; values = null; return(false); } string[] rawValues = readNextRecord(); ++recordCount; if (schema == null) { values = rawValues; } else if (rawValues.Length < schema.ColumnDefinitions.HandledCount) { hasError = true; throw new FlatFileException(SharedResources.SeparatedValueRecordWrongNumberOfColumns, recordCount); } else { values = schema.ParseValues(rawValues); } return(true); }
private object[] parseValues(string[] rawValues) { if (schema == null) { return(rawValues); } try { return(schema.ParseValues(rawValues)); } catch (FlatFileException exception) { processError(new RecordProcessingException(recordCount, SharedResources.InvalidRecordConversion, exception)); return(null); } }
private object[] parseValues(SeparatedValueSchema schema, string[] rawValues) { if (schema == null) { return(rawValues); } try { var metadata = schemaSelector == null ? this.metadata : new Metadata() { Schema = schema, Options = this.metadata.Options, RecordCount = this.metadata.RecordCount, LogicalRecordCount = this.metadata.LogicalRecordCount }; return(schema.ParseValues(metadata, rawValues)); } catch (FlatFileException exception) { processError(new RecordProcessingException(metadata.RecordCount, Resources.InvalidRecordConversion, exception)); return(null); } }
/// <summary> /// Parses the given values assuming that they are in the same order as the column definitions. /// </summary> /// <param name="values">The values to parse.</param> /// <returns>The parsed objects.</returns> internal object[] ParseValues(string[] values) { return(schema.ParseValues(values)); }