Esempio n. 1
0
        /// <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 )}.");
            }
        }
Esempio n. 2
0
        /// <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;
        }
Esempio n. 3
0
        /// <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;
        }
Esempio n. 4
0
 /// <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;
 }
Esempio n. 5
0
 /// <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)
 {
 }
Esempio n. 6
0
 /// <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)
 {
 }
Esempio n. 8
0
 /// <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)
 {
 }
Esempio n. 9
0
 /// <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;
 }
Esempio n. 10
0
 /// <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;
 }
Esempio n. 11
0
 /// <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;
 }
Esempio n. 12
0
 /// <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.");
 }
Esempio n. 13
0
 /// <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)}.");
 }
Esempio n. 14
0
 /// <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)
 {
 }
Esempio n. 15
0
 /// <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)
 {
 }
Esempio n. 16
0
 /// <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)
 {
 }
Esempio n. 17
0
 /// <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)
 {
 }
Esempio n. 18
0
 /// <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);
 }
Esempio n. 19
0
 /// <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)
 {
 }
Esempio n. 20
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CsvHelperException"/> class.
 /// </summary>
 public CsvHelperException(ReadingContext context)
 {
     readingContext = context;
 }
Esempio n. 21
0
 /// <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;
 }
Esempio n. 22
0
 /// <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)
 {
 }
Esempio n. 24
0
 /// <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)
 {
 }
Esempio n. 26
0
 /// <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)
 {
 }
Esempio n. 27
0
 /// <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;
 }