/// <summary> /// Creates a new parser using the given <see cref="FieldReader"/>. /// </summary> /// <param name="fieldReader">The field reader.</param> public CsvParser(IFieldReader fieldReader) { //this.fieldReader = fieldReader ?? throw new ArgumentNullException( nameof( fieldReader ) ); this.fieldReader = CSharp6Extension.GetArgumentOrThrowException <IFieldReader>(fieldReader, nameof(fieldReader)); //context = fieldReader.Context as ReadingContext ?? throw new InvalidOperationException( $"For {nameof( FieldReader )} to be used in {nameof( CsvParser )}, {nameof( FieldReader.Context )} must also implement {nameof( ReadingContext )}." ); context = fieldReader.Context as ReadingContext; if (context == null) { throw new InvalidOperationException($"For {nameof( FieldReader )} to be used in {nameof( CsvParser )}, {nameof( FieldReader.Context )} must also implement {nameof( ReadingContext )}."); } }
/// <summary> /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. /// </summary> /// <param name="disposing">True if the instance needs to be disposed of.</param> protected virtual void Dispose(bool disposing) { if (disposed) { return; } if (disposing) { context?.Dispose(); } context = null; disposed = true; }
/// <summary> /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. /// </summary> /// <param name="disposing">True if the instance needs to be disposed of.</param> protected virtual void Dispose(bool disposing) { if (disposed) { return; } if (disposing) { fieldReader?.Dispose(); } fieldReader = null; context = null; disposed = true; }
/// <summary> /// Initializes a new instance of the <see cref="ValidationException"/> class /// with a specified error message and a reference to the inner exception that /// is the cause of this exception. /// </summary> /// <param name="context">The reading context.</param> /// <param name="field">The field that failed validation.</param> /// <param name="message">The error message that explains the reason for the exception.</param> /// <param name="innerException">The exception that is the cause of the current exception, or a null reference (Nothing in Visual Basic) if no inner exception is specified.</param> public FieldValidationException(ReadingContext context, string field, string message, Exception innerException) : base(context, message, innerException) { Field = field; }
/// <summary> /// Initializes a new instance of the <see cref="ValidationException"/> class /// with a specified error message. /// </summary> /// <param name="context">The reading context.</param> /// <param name="message">The message that describes the error.</param> public ValidationException(ReadingContext context, string message) : base(context, message) { }
/// <summary> /// Initializes a new instance of the <see cref="ValidationException"/> class. /// </summary> /// <param name="context">The reading context.</param> /// <param name="field">The field that failed validation.</param> public FieldValidationException(ReadingContext context, string field) : base(context) { Field = field; }
/// <summary> /// Initializes a new instance of the <see cref="CsvMissingFieldException"/> class /// with a specified error message and a reference to the inner exception that /// is the cause of this exception. /// </summary> /// <param name="context">The reading context.</param> /// <param name="message">The error message that explains the reason for the exception.</param> /// <param name="innerException">The exception that is the cause of the current exception, or a null reference (Nothing in Visual Basic) if no inner exception is specified.</param> public CsvMissingFieldException(ReadingContext context, string message, Exception innerException) : base(context, message, innerException) { }
/// <summary> /// Initializes a new instance of the <see cref="ValidationException"/> class. /// </summary> /// <param name="context">The reading context.</param> public ValidationException(ReadingContext context) : base(context) { }
/// <summary> /// Initializes a new instance of the <see cref="ValidationException"/> class /// with a specified error message and a reference to the inner exception that /// is the cause of this exception. /// </summary> /// <param name="context">The reading context.</param> /// <param name="headerNames">The header names that are mapped to a CSV field that couldn't be found.</param> /// <param name="headerNameIndex">The header name index that is mapped to a CSV field that couldn't be found.</param> /// <param name="message">The error message that explains the reason for the exception.</param> /// <param name="innerException">The exception that is the cause of the current exception, or a null reference (Nothing in Visual Basic) if no inner exception is specified.</param> public HeaderValidationException(ReadingContext context, string[] headerNames, int?headerNameIndex, string message, Exception innerException) : base(context, message, innerException) { HeaderNames = headerNames; HeaderNameIndex = headerNameIndex; }
/// <summary> /// Initializes a new instance of the <see cref="ValidationException"/> class /// with a specified error message and a reference to the inner exception that /// is the cause of this exception. /// </summary> /// <param name="context">The reading context.</param> /// <param name="invalidHeaders">The invalid headers.</param> /// <param name="message">The error message that explains the reason for the exception.</param> /// <param name="innerException">The exception that is the cause of the current exception, or a null reference (Nothing in Visual Basic) if no inner exception is specified.</param> public HeaderValidationException(ReadingContext context, InvalidHeader[] invalidHeaders, string message, Exception innerException) : base(context, message, innerException) { InvalidHeaders = invalidHeaders; }
/// <summary> /// Initializes a new instance of the <see cref="CsvHelperException"/> class /// with a specified error message. /// </summary> /// <param name="context">The reading context.</param> /// <param name="message">The message that describes the error.</param> public CsvHelperException(ReadingContext context, string message) : base(message) { ReadingContext = context; }
/// <summary> /// Creates a new parser using the given <see cref="FieldReader"/>. /// </summary> /// <param name="fieldReader">The field reader.</param> public CsvParser(IFieldReader fieldReader) { this.fieldReader = fieldReader ?? throw new ArgumentNullException(nameof(fieldReader)); context = fieldReader.Context as ReadingContext ?? throw new InvalidOperationException("For FieldReader to be used in CsvParser, FieldReader.Context must also implement IParserContext."); }
/// <summary> /// Creates a new parser using the given <see cref="FieldReader"/>. /// </summary> /// <param name="fieldReader">The field reader.</param> public CsvParser(IFieldReader fieldReader) { this.fieldReader = fieldReader ?? throw new ArgumentNullException(nameof(fieldReader)); context = fieldReader.Context as ReadingContext ?? throw new InvalidOperationException($"For {nameof(FieldReader)} to be used in {nameof(CsvParser)}, {nameof(FieldReader.Context)} must also implement {nameof(ReadingContext)}."); }
/// <summary> /// Initializes a new instance of the <see cref="CsvReaderException"/> class. /// </summary> /// <param name="context">The reading context.</param> public CsvReaderException(ReadingContext context) : base(context) { }
/// <summary> /// Initializes a new instance of the <see cref="BadDataException"/> class /// with a specified error message. /// </summary> /// <param name="context">The reading context.</param> /// <param name="message">The message that describes the error.</param> public BadDataException(ReadingContext context, string message) : base(context, message) { }
/// <summary> /// Initializes a new instance of the <see cref="BadDataException"/> class. /// </summary> /// <param name="context">The reading context.</param> public BadDataException(ReadingContext context) : base(context) { }
/// <summary> /// Initializes a new instance of the <see cref="CsvBadDataException"/> class /// with a specified error message and a reference to the inner exception that /// is the cause of this exception. /// </summary> /// <param name="context">The reading context.</param> /// <param name="message">The error message that explains the reason for the exception.</param> /// <param name="innerException">The exception that is the cause of the current exception, or a null reference (Nothing in Visual Basic) if no inner exception is specified.</param> public CsvBadDataException(ReadingContext context, string message, Exception innerException) : base(context, message, innerException) { }
/// <summary> /// Creates a new <see cref="CsvFieldReader"/> using the given /// <see cref="TextReader"/>, <see cref="Configuration.Configuration"/> /// and leaveOpen flag. /// </summary> /// <param name="reader">The text reader.</param> /// <param name="configuration">The configuration.</param> /// <param name="leaveOpen">A value indicating if the <see cref="TextReader"/> should be left open when disposing.</param> public CsvFieldReader(TextReader reader, Configuration.Configuration configuration, bool leaveOpen) { context = new ReadingContext(reader, configuration, leaveOpen); }
/// <summary> /// Initializes a new instance of the <see cref="ParserException"/> class /// with a specified error message. /// </summary> /// <param name="context">The reading context.</param> /// <param name="message">The message that describes the error.</param> public ParserException(ReadingContext context, string message) : base(context, message) { }
/// <summary> /// Initializes a new instance of the <see cref="CsvHelperException"/> class. /// </summary> public CsvHelperException(ReadingContext context) { readingContext = context; }
/// <summary> /// Initializes a new instance of the <see cref="ValidationException"/> class. /// </summary> /// <param name="context">The reading context.</param> /// <param name="headerNames">The header names that are mapped to a CSV field that couldn't be found.</param> /// <param name="headerNameIndex">The header name index that is mapped to a CSV field that couldn't be found.</param> public HeaderValidationException(ReadingContext context, string[] headerNames, int?headerNameIndex) : base(context) { HeaderNames = headerNames; HeaderNameIndex = headerNameIndex; }
/// <summary> /// Initializes a new instance of the <see cref="CsvHelperException"/> class /// with a specified error message and a reference to the inner exception that /// is the cause of this exception. /// </summary> /// <param name="context">The reading context.</param> /// <param name="message">The error message that explains the reason for the exception.</param> /// <param name="innerException">The exception that is the cause of the current exception, or a null reference (Nothing in Visual Basic) if no inner exception is specified.</param> public CsvHelperException(ReadingContext context, string message, Exception innerException) : base(message, innerException) { readingContext = context; }
/// <summary> /// Initializes a new instance of the <see cref="CsvMissingFieldException"/> class. /// </summary> /// <param name="context">The reading context.</param> public CsvMissingFieldException(ReadingContext context) : base(context) { }
/// <summary> /// Initializes a new instance of the <see cref="ParserException"/> class. /// </summary> /// <param name="context">The reading context.</param> public ParserException(ReadingContext context) : base(context) { }
/// <summary> /// Initializes a new instance of the <see cref="CsvMissingFieldException"/> class /// with a specified error message. /// </summary> /// <param name="context">The reading context.</param> /// <param name="message">The message that describes the error.</param> public CsvMissingFieldException(ReadingContext context, string message) : base(context, message) { }
/// <summary> /// Initializes a new instance of the <see cref="ParserException"/> class /// with a specified error message and a reference to the inner exception that /// is the cause of this exception. /// </summary> /// <param name="context">The reading context.</param> /// <param name="message">The error message that explains the reason for the exception.</param> /// <param name="innerException">The exception that is the cause of the current exception, or a null reference (Nothing in Visual Basic) if no inner exception is specified.</param> public ParserException(ReadingContext context, string message, Exception innerException) : base(context, message, innerException) { }
/// <summary> /// Initializes a new instance of the <see cref="ValidationException"/> class. /// </summary> /// <param name="context">The reading context.</param> /// <param name="invalidHeaders">The invalid headers.</param> public HeaderValidationException(ReadingContext context, InvalidHeader[] invalidHeaders) : base(context) { InvalidHeaders = invalidHeaders; }