Exemplo n.º 1
0
        //,*[ \t]*\"(?<value>(?:\"\"|[^\"\n\f\r])*)\"|(?<value>[^,\n\f\r\"]*))
        //const string _csvRegexPattern = ",*[ \t]*\"(?<value>(?:\"\"|[^\"\n\f\r])*)\"|(?<value>[^,\n\f\r\"]*))";

        public CsvReader()
        {
            _columns = new CsvColumn[TypeInfoCache <T> .ReadWriteProperties.Length];
            for (var i = 0; i < _columns.Length; ++i)
            {
                _columns[i] = new CsvColumn()
                {
                    OrdinalPosition = i,
                    PropertyName    = TypeInfoCache <T> .ReadWritePropertyNames[i],
                    PropertyInfo    = TypeInfoCache <T> .ReadWriteProperties[i]
                };
            }
        }
Exemplo n.º 2
0
        internal static string GetStringValueFromCaptures(CaptureCollection captures, int positionOffset, CsvColumn column)
        {
            var value = captures[column.OrdinalPosition + positionOffset].Value;

            if (value != null)
            {
                // remove double quotes which are CSV escapes according to RFC 4180
                value = value.Replace("\"\"", "\"");
                if (value == string.Empty)
                {
                    value = column.DefaultValue;
                }
                else
                {
                    column.ValidateValue(value);
                }
            }
            else
            {
                value = column.DefaultValue;
            }
            return(value);
        }