Ejemplo n.º 1
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));
            if (!(this.serializer.Context is IWriterContext))
            {
                throw new InvalidOperationException("For ICsvSerializer to be used in CsvWriter, ICsvSerializer.Context must also implement IWriterContext.");
            }

            context = serializer.Context;
        }
Ejemplo n.º 2
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);
 }
Ejemplo 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 async ValueTask DisposeAsync(bool disposing)
        {
            if (disposed)
            {
                return;
            }

            if (disposing && context != null)
            {
                await context.DisposeAsync().ConfigureAwait(false);
            }

            context  = null;
            disposed = true;
        }
Ejemplo n.º 4
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;
        }
Ejemplo n.º 5
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)
            {
                serializer?.Dispose();
            }

            serializer = null;
            context    = null;
            disposed   = true;
        }
Ejemplo n.º 6
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 async ValueTask DisposeAsync(bool disposing)
        {
            if (disposed)
            {
                return;
            }

            await FlushAsync().ConfigureAwait(false);

            if (disposing && serializer != null)
            {
                await serializer.DisposeAsync().ConfigureAwait(false);
            }

            serializer = null;
            context    = null;
            disposed   = true;
        }
Ejemplo n.º 7
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;
            }

            Flush();

            if (disposing)
            {
                //serializer?.Dispose();
                if (serializer != null)
                {
                    serializer.Dispose();
                }
            }

            serializer = null;
            context    = null;
            disposed   = true;
        }
Ejemplo n.º 8
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));
     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)}.");
     recordManager   = new Lazy <RecordManager>(() => ObjectResolver.Current.Resolve <RecordManager>(this));
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CsvHelperException"/> class.
 /// </summary>
 public CsvHelperException(WritingContext context)
 {
     writingContext = context;
 }
Ejemplo n.º 10
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 writing 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(WritingContext context, string message, Exception innerException) : base(message, innerException)
 {
     writingContext = context;
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="WriterException"/> 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 writing 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 WriterException(WritingContext context, string message, Exception innerException) : base(context, message, innerException)
 {
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="WriterException"/> class
 /// with a specified error message.
 /// </summary>
 /// <param name="context">The writing context.</param>
 /// <param name="message">The message that describes the error.</param>
 public WriterException(WritingContext context, string message) : base(context, message)
 {
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="WriterException"/> class.
 /// </summary>
 /// <param name="context">The writing context.</param>
 public WriterException(WritingContext context) : base(context)
 {
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Creates a new serializer using the given <see cref="TextWriter"/>
 /// and <see cref="CsvHelper.Configuration.CsvConfiguration"/>.
 /// </summary>
 /// <param name="writer">The <see cref="TextWriter"/> to write the CSV file data to.</param>
 /// <param name="configuration">The configuration.</param>
 /// <param name="leaveOpen">true to leave the reader open after the CsvReader object is disposed, otherwise false.</param>
 public CsvSerializer(TextWriter writer, Configuration.CsvConfiguration configuration, bool leaveOpen)
 {
     context = new WritingContext(writer, configuration, leaveOpen);
 }
Ejemplo n.º 15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CsvHelperException"/> class
 /// with a specified error message.
 /// </summary>
 /// <param name="context">The writing context.</param>
 /// <param name="message">The message that describes the error.</param>
 public CsvHelperException(WritingContext context, string message) : base(message)
 {
     WritingContext = context;
 }