/// <summary>
 /// Initializes a new instance.
 /// </summary>
 /// <param name="reader">The reader.</param>
 /// <param name="configuration">The configuration.</param>
 /// <param name="leaveOpen">A value indicating if the TextReader should be left open when disposing.</param>
 public ReadingContext(TextReader reader, Configuration.Configuration configuration, bool leaveOpen)
 {
     //Reader = reader ?? throw new ArgumentNullException( nameof( reader ) );
     Reader = CSharp6Extension.GetArgumentOrThrowException <TextReader>(reader, nameof(reader));                                            // ?? throw new ArgumentNullException( nameof( reader ) );
     //this.configuration = configuration ?? throw new ArgumentNullException( nameof( configuration ) );
     this.configuration = CSharp6Extension.GetArgumentOrThrowException <Configuration.Configuration>(configuration, nameof(configuration)); //configuration ?? throw new ArgumentNullException( nameof( configuration ) );
     LeaveOpen          = leaveOpen;
     Buffer             = new char[0];
 }
 /// <summary>
 /// Creates a new CSV writer using the given <see cref="ISerializer"/>.
 /// </summary>
 /// <param name="serializer">The serializer.</param>
 public CsvWriter(ISerializer serializer)
 {
     //this.serializer = serializer ?? throw new ArgumentNullException( nameof( serializer ) );
     this.serializer = CSharp6Extension.GetArgumentOrThrowException <ISerializer>(serializer, nameof(serializer));
     //context = serializer.Context as WritingContext ?? throw new InvalidOperationException( $"For {nameof( ISerializer )} to be used in {nameof( CsvWriter )}, {nameof( ISerializer.Context )} must also implement {nameof( WritingContext )}." );
     context = serializer.Context as WritingContext;
     if (context == null)
     {
         throw new InvalidOperationException($"For {nameof( ISerializer )} to be used in {nameof( CsvWriter )}, {nameof( ISerializer.Context )} must also implement {nameof( WritingContext )}.");
     }
     recordManager = ObjectResolver.Current.Resolve <RecordManager>(this);
 }
示例#3
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 )}.");
            }
        }