示例#1
0
        internal CsvConfiguration GetCurrentConfiguration()
        {
            var currentConfiguration = new CsvConfiguration
            {
                Delimiter        = FieldDelimiter.GetValue().ToString(),
                SkipEmptyRecords = true,
                Quote            = '█' //,
                                       //QuoteNoFields = true
            };
            var allProperties = CurrentInterchangeRecordType.GetProperties();

            //map all the public properties with their indexes.
            foreach (var propertyInfo in allProperties)
            {
                var currentPropertyInfo = propertyInfo;
                var mapping             = CurrentFieldMappings.Keys.SingleOrDefault(p => p == currentPropertyInfo.Name);
                //if the mapping does not exit or equals -1, ignore it.
                if (mapping == null || CurrentFieldMappings[mapping] == -1)
                {
                    currentConfiguration.PropertyMap(currentPropertyInfo).Ignore();
                }
                else
                {
                    currentConfiguration.Properties.Add(
                        currentConfiguration.PropertyMap(currentPropertyInfo).Index(CurrentFieldMappings[mapping]));
                }
            }

            return(currentConfiguration);
        }
示例#2
0
 public static string[] GetFieldHeaders(string filePath, Delimiter fieldDelimiter)
 {
     using (var csvReader = new CsvReader(File.OpenText(filePath)))
     {
         csvReader.Configuration.Delimiter = fieldDelimiter.GetValue().ToString();
         return(csvReader.FieldHeaders);
     }
 }