private SeparatedValueParser(Stream stream, Schema schema, SeparatedValueParserOptions options, bool hasSchema) { if (stream == null) { throw new ArgumentNullException("stream"); } if (hasSchema && schema == null) { throw new ArgumentNullException("schema"); } if (options == null) { throw new ArgumentNullException("options"); } this.stream = stream; StreamReader reader = new StreamReader(stream); this.text = reader.ReadToEnd(); regex = buildRegex(options.Separator); if (hasSchema) { if (options.IsFirstRecordSchema) { readNextRecord(); // skip header record } this.schema = schema; } else if (options.IsFirstRecordSchema) { string[] columnNames = readNextRecord(); this.schema = new Schema(); foreach (string columnName in columnNames) { StringColumn column = new StringColumn(columnName); this.schema.AddColumn(column); } } }
/// <summary> /// Initializes a new instance of a SeparatedValueParser. /// </summary> /// <param name="fileName">The path of the file containing the records to extract.</param> /// <param name="schema">The predefined schema for the records.</param> /// <param name="options">The options for configuring the parser's behavior.</param> /// <exception cref="System.ArgumentNullException">The schema is null.</exception> /// <exception cref="System.ArgumentNullException">The options object is null.</exception> public SeparatedValueParser(string fileName, Schema schema, SeparatedValueParserOptions options) : this(File.OpenRead(fileName), schema, options, true) { }
/// <summary> /// Initializes a new instance of a SeparatedValueParser. /// </summary> /// <param name="fileName">The path of the file containing the records to extract.</param> /// <param name="options">The options for configuring the parser's behavior.</param> /// <exception cref="System.ArgumentNullException">The options object is null.</exception> public SeparatedValueParser(string fileName, SeparatedValueParserOptions options) : this(File.OpenRead(fileName), null, options, false) { }
/// <summary> /// Initializes a new instance of a SeparatedValueParser. /// </summary> /// <param name="stream">A stream containing the records to parse.</param> /// <param name="schema">The predefined schema for the records.</param> /// <param name="options">The options for configuring the parser's behavior.</param> /// <exception cref="System.ArgumentNullException">The stream is null.</exception> /// <exception cref="System.ArgumentNullException">The schema is null.</exception> /// <exception cref="System.ArgumentNullException">The options object is null.</exception> public SeparatedValueParser(Stream stream, Schema schema, SeparatedValueParserOptions options) : this(stream, schema, options, true) { }
/// <summary> /// Initializes a new instance of a SeparatedValueParser. /// </summary> /// <param name="stream">A stream containing the records to parse.</param> /// <param name="options">The options for configuring the parser's behavior.</param> /// <exception cref="System.ArgumentNullException">The stream is null.</exception> /// <exception cref="System.ArgumentNullException">The options object is null.</exception> public SeparatedValueParser(Stream stream, SeparatedValueParserOptions options) : this(stream, null, options, false) { }