示例#1
0
        /// <summary>
        /// Constructs a new <see cref="FixedWidthReader"/> instance.
        /// </summary>
        /// <param name="fields">List of fixed-width field descriptors.</param>
        /// <param name="filename">File to read.</param>
        /// <param name="detectEncodingFromByteOrderMarks">Indicates whether to look for byte order marks at the beginning of the file.</param>
        /// <param name="options">Library options. Leave as null to use the default options.</param>
        /// <exception cref="ArgumentNullException"></exception>
        public FixedWidthReader(IEnumerable <FixedWidthField> fields, string filename, bool detectEncodingFromByteOrderMarks, FixedWidthOptions?options = null)
        {
            if (fields == null)
            {
                throw new ArgumentNullException(nameof(fields));
            }
            if (filename == null)
            {
                throw new ArgumentNullException(nameof(filename));
            }

            Fields  = new List <FixedWidthField>(fields);
            Reader  = new StreamReader(filename, detectEncodingFromByteOrderMarks);
            Options = options ?? new FixedWidthOptions();
        }
        /// <summary>
        /// Constructs a new <see cref="FixedWidthWriter"/> instance.
        /// </summary>
        /// <param name="fields">List of fixed-width field descriptors.</param>
        /// <param name="filename">File to write.</param>
        /// <param name="options">Library options. Leave as null to use the default options.</param>
        /// <exception cref="ArgumentNullException"></exception>
        public FixedWidthWriter(IEnumerable <FixedWidthField> fields, string filename, FixedWidthOptions?options = null)
        {
            if (fields == null)
            {
                throw new ArgumentNullException(nameof(fields));
            }
            if (filename == null)
            {
                throw new ArgumentNullException(nameof(filename));
            }

            Fields  = new List <FixedWidthField>(fields);
            Writer  = new StreamWriter(filename);
            Options = options ?? new FixedWidthOptions();
        }
示例#3
0
        /// <summary>
        /// Constructs a new <see cref="FixedWidthReader"/> instance.
        /// </summary>
        /// <param name="fields">List of fixed-width field descriptors.</param>
        /// <param name="stream">Stream to read.</param>
        /// <param name="options">Library options. Leave as null to use the default options.</param>
        /// <exception cref="ArgumentNullException"></exception>
        public FixedWidthReader(IEnumerable <FixedWidthField> fields, Stream stream, FixedWidthOptions?options = null)
        {
            if (fields == null)
            {
                throw new ArgumentNullException(nameof(fields));
            }
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            Fields  = new List <FixedWidthField>(fields);
            Reader  = new StreamReader(stream);
            Options = options ?? new FixedWidthOptions();
        }
示例#4
0
        /// <summary>
        /// Constructs a new <see cref="FixedWidthReader"/> instance.
        /// </summary>
        /// <param name="fields">List of fixed-width field descriptors.</param>
        /// <param name="filename">File to read.</param>
        /// <param name="encoding">The character encoding to use.</param>
        /// <param name="options">Library options. Leave as null to use the default options.</param>
        /// <exception cref="ArgumentNullException"></exception>
        public FixedWidthReader(IEnumerable <FixedWidthField> fields, string filename, Encoding encoding, FixedWidthOptions?options = null)
        {
            if (fields == null)
            {
                throw new ArgumentNullException(nameof(fields));
            }
            if (filename == null)
            {
                throw new ArgumentNullException(nameof(filename));
            }
            if (encoding == null)
            {
                throw new ArgumentNullException(nameof(encoding));
            }

            Fields  = new List <FixedWidthField>(fields);
            Reader  = new StreamReader(filename, encoding);
            Options = options ?? new FixedWidthOptions();
        }
        /// <summary>
        /// Constructs a new <see cref="FixedWidthWriter"/> instance.
        /// </summary>
        /// <param name="fields">List of fixed-width field descriptors.</param>
        /// <param name="stream">Stream to write.</param>
        /// <param name="encoding">The character encoding to use.</param>
        /// <param name="options">Library options. Leave as null to use the default options.</param>
        /// <exception cref="ArgumentNullException"></exception>
        public FixedWidthWriter(IEnumerable <FixedWidthField> fields, Stream stream, Encoding encoding, FixedWidthOptions?options = null)
        {
            if (fields == null)
            {
                throw new ArgumentNullException(nameof(fields));
            }
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }
            if (encoding == null)
            {
                throw new ArgumentNullException(nameof(encoding));
            }

            Fields  = new List <FixedWidthField>(fields);
            Writer  = new StreamWriter(stream, encoding);
            Options = options ?? new FixedWidthOptions();
        }