diff --git a/LINQtoCSV/CsvFileDescription.cs b/LINQtoCSV/CsvFileDescription.cs index b983ca8..f018586 100644 --- a/LINQtoCSV/CsvFileDescription.cs +++ b/LINQtoCSV/CsvFileDescription.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Globalization; using System.Text; @@ -90,7 +91,12 @@ public int MaximumNbrExceptions public bool UseFieldIndexForReadingData { get; set; } public bool UseOutputFormatForParsingCsvValue { get; set; } public bool IgnoreTrailingSeparatorChar { get; set; } - + + /// + /// Allows for override of the string comparison strategy + /// + public IEqualityComparer ColumnEqualityComparer { get; set; } + /// /// If set to true, wil read only the fields specified as attributes, and will discard other fields in the CSV file /// diff --git a/LINQtoCSV/FieldMapper.cs b/LINQtoCSV/FieldMapper.cs index 9ef9dfc..853fa4e 100644 --- a/LINQtoCSV/FieldMapper.cs +++ b/LINQtoCSV/FieldMapper.cs @@ -267,7 +267,9 @@ public FieldMapper(CsvFileDescription fileDescription, string fileName, bool wri m_fileDescription = fileDescription; m_fileName = fileName; - m_NameToInfo = new Dictionary(); + m_NameToInfo = fileDescription.ColumnEqualityComparer != null ? + new Dictionary(fileDescription.ColumnEqualityComparer) : + new Dictionary(); AnalyzeType( typeof(T), diff --git a/TestConsoleApplication/ProductData.cs b/TestConsoleApplication/ProductData.cs index 847c9f2..bbe0f1e 100644 --- a/TestConsoleApplication/ProductData.cs +++ b/TestConsoleApplication/ProductData.cs @@ -25,7 +25,7 @@ class ProductData public DateTime launchTime; // Can use both fields and properties - [CsvColumn(FieldIndex = 4, CanBeNull = false, OutputFormat = "#,000.000")] + [CsvColumn(FieldIndex = 4, CanBeNull = false, OutputFormat = "#,000.000", Name = "Weight")] public double weight { get; set; } // Following field has no CsvColumn attribute. diff --git a/TestConsoleApplication/Program.cs b/TestConsoleApplication/Program.cs index e82ff17..60fdaf9 100644 --- a/TestConsoleApplication/Program.cs +++ b/TestConsoleApplication/Program.cs @@ -29,7 +29,8 @@ static void Main(string[] args) SeparatorChar = ',', // default is ',' FirstLineHasColumnNames = true, EnforceCsvColumnAttribute = false, // default is false - FileCultureName = "en-US" // default is the current culture + FileCultureName = "en-US", // default is the current culture + ColumnEqualityComparer = StringComparer.CurrentCultureIgnoreCase }; try diff --git a/TestConsoleApplication/TestFiles/output_anon.csv b/TestConsoleApplication/TestFiles/output_anon.csv index f22ff9c..4f91285 100644 --- a/TestConsoleApplication/TestFiles/output_anon.csv +++ b/TestConsoleApplication/TestFiles/output_anon.csv @@ -1,4 +1,4 @@ Markup,InShops,ProductName -39150.0,2/01/1985 12:00:00 AM,mouse trap -270.060,23/05/2008 12:00:00 AM,moonbuggy -6004.0,29/02/2004 12:00:00 AM,dog house +39150.0,1/2/1985 12:00:00 AM,mouse trap +270.060,5/23/2008 12:00:00 AM,moonbuggy +6004.0,2/29/2004 12:00:00 AM,dog house diff --git a/TestConsoleApplication/TestFiles/output_names_nl.csv b/TestConsoleApplication/TestFiles/output_names_nl.csv index f7ec0a3..4a701a7 100644 Binary files a/TestConsoleApplication/TestFiles/output_names_nl.csv and b/TestConsoleApplication/TestFiles/output_names_nl.csv differ diff --git a/TestConsoleApplication/TestFiles/output_newdata_names_nl.csv b/TestConsoleApplication/TestFiles/output_newdata_names_nl.csv index 35c7ee0..d8ba3ad 100644 Binary files a/TestConsoleApplication/TestFiles/output_newdata_names_nl.csv and b/TestConsoleApplication/TestFiles/output_newdata_names_nl.csv differ