Beispiel #1
0
        internal void Validate(ChoRecordConfiguration config)
        {
            StringComparer = StringComparer.Create(_culture == null ? CultureInfo.CurrentCulture : _culture, IgnoreCase);

            if (FillChar == ChoCharEx.NUL)
            {
                throw new ChoRecordConfigurationException("Invalid '{0}' FillChar specified.".FormatString(FillChar));
            }

            if (config is ChoCSVRecordConfiguration)
            {
                ChoCSVRecordConfiguration csvConfig = config as ChoCSVRecordConfiguration;

                if (csvConfig.Delimiter.Contains(FillChar))
                {
                    throw new ChoRecordConfigurationException("FillChar [{0}] can't be one of Delimiter characters [{1}]".FormatString(FillChar, csvConfig.Delimiter));
                }
                if (csvConfig.EOLDelimiter.Contains(FillChar))
                {
                    throw new ChoRecordConfigurationException("FillChar [{0}] can't be one EOLDelimiter characters [{1}]".FormatString(FillChar, csvConfig.EOLDelimiter));
                }
                if ((from comm in csvConfig.Comments
                     where comm.Contains(FillChar.ToString())
                     select comm).Any())
                {
                    throw new ChoRecordConfigurationException("One of the Comments contains FillChar. Not allowed.");
                }
            }
        }
Beispiel #2
0
        internal void Validate(ChoCSVRecordConfiguration config)
        {
            try
            {
                if (FieldPosition < 0)
                {
                    throw new ChoRecordConfigurationException("Invalid '{0}' field position specified. Must be > 0.".FormatString(FieldPosition));
                }
                if (FillChar == ChoCharEx.NUL)
                {
                    throw new ChoRecordConfigurationException("Invalid '{0}' FillChar specified.".FormatString(FillChar));
                }
                if (config.Delimiter.Contains(FillChar))
                {
                    throw new ChoRecordConfigurationException("FillChar [{0}] can't be one of Delimiter characters [{1}]".FormatString(FillChar, config.Delimiter));
                }
                if (config.EOLDelimiter.Contains(FillChar))
                {
                    throw new ChoRecordConfigurationException("FillChar [{0}] can't be one EOLDelimiter characters [{1}]".FormatString(FillChar, config.EOLDelimiter));
                }
                if ((from comm in config.Comments
                     where comm.Contains(FillChar.ToString())
                     select comm).Any())
                {
                    throw new ChoRecordConfigurationException("One of the Comments contains FillChar. Not allowed.");
                }

                if (Size != null && Size.Value <= 0)
                {
                    throw new ChoRecordConfigurationException("Size must be > 0.");
                }
                if (ErrorMode == null)
                {
                    ErrorMode = config.ErrorMode;
                }
                if (IgnoreFieldValueMode == null)
                {
                    IgnoreFieldValueMode = config.IgnoreFieldValueMode;
                }
                if (QuoteField == null)
                {
                    QuoteField = config.QuoteAllFields;
                }
            }
            catch (Exception ex)
            {
                throw new ChoRecordConfigurationException("Invalid configuration found at '{0}' field.".FormatString(Name), ex);
            }
        }