Exemple #1
0
        public CSVWriter(Dialect dialect, string filename, string encoding, CultureInfo culture = null)
        {
            if (dialect == null)
            {
                throw new DialectIsNullException("Set dialect first!");
            }
            dialect.Check();
            _dialect = dialect;

            if (_writer == null)
            {
                if (string.IsNullOrEmpty(filename) || filename.Trim().Length < 1)
                {
                    throw new FileNameIsNullOrEmptyException();
                }

                if (!File.Exists(filename))
                {
                    throw new CannotWriteToFileException(string.Format("Can't write to file: '{0}', file not exists!", filename));
                }

                _ownsWriter = true;
                try
                {
                    _writer = new StreamWriter(filename, false, Encoding.GetEncoding(encoding));
                }
                catch (Exception exp)
                {
                    throw new CannotWriteToFileException(string.Format("Can't write to file: '{0}'!", filename), exp);
                }
            }

            _culture = culture ?? Thread.CurrentThread.CurrentCulture;
        }
Exemple #2
0
        public CSVWriter(Dialect dialect, TextWriter writer, CultureInfo culture = null)
        {
            if (dialect == null)
            {
                throw new DialectIsNullException("Set dialect first!");
            }
            dialect.Check();
            _dialect = dialect;

            if (writer != null)
            {
                _writer = writer;
            }

            _culture = culture ?? Thread.CurrentThread.CurrentCulture;
        }