Skip to content

Commit 874c035

Browse files
author
William Hesketh
authored
Merge pull request #3 from mannyta/master
Merge fork
2 parents 1a53d15 + 95253c4 commit 874c035

File tree

7 files changed

+16
-7
lines changed

7 files changed

+16
-7
lines changed

LINQtoCSV/CsvFileDescription.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.Globalization;
34
using System.Text;
45

@@ -90,7 +91,12 @@ public int MaximumNbrExceptions
9091
public bool UseFieldIndexForReadingData { get; set; }
9192
public bool UseOutputFormatForParsingCsvValue { get; set; }
9293
public bool IgnoreTrailingSeparatorChar { get; set; }
93-
94+
95+
/// <summary>
96+
/// Allows for override of the string comparison strategy
97+
/// </summary>
98+
public IEqualityComparer<string> ColumnEqualityComparer { get; set; }
99+
94100
/// <summary>
95101
/// If set to true, wil read only the fields specified as attributes, and will discard other fields in the CSV file
96102
/// </summary>

LINQtoCSV/FieldMapper.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,9 @@ public FieldMapper(CsvFileDescription fileDescription, string fileName, bool wri
269269
m_fileDescription = fileDescription;
270270
m_fileName = fileName;
271271

272-
m_NameToInfo = new Dictionary<string, TypeFieldInfo>();
272+
m_NameToInfo = fileDescription.ColumnEqualityComparer != null ?
273+
new Dictionary<string, TypeFieldInfo>(fileDescription.ColumnEqualityComparer) :
274+
new Dictionary<string, TypeFieldInfo>();
273275

274276
AnalyzeType(
275277
typeof(T),

TestConsoleApplication/ProductData.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class ProductData
2525
public DateTime launchTime;
2626

2727
// Can use both fields and properties
28-
[CsvColumn(FieldIndex = 4, CanBeNull = false, OutputFormat = "#,000.000")]
28+
[CsvColumn(FieldIndex = 4, CanBeNull = false, OutputFormat = "#,000.000", Name = "Weight")]
2929
public double weight { get; set; }
3030

3131
// Following field has no CsvColumn attribute.

TestConsoleApplication/Program.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ static void Main(string[] args)
2929
SeparatorChar = ',', // default is ','
3030
FirstLineHasColumnNames = true,
3131
EnforceCsvColumnAttribute = false, // default is false
32-
FileCultureName = "en-US" // default is the current culture
32+
FileCultureName = "en-US", // default is the current culture
33+
ColumnEqualityComparer = StringComparer.CurrentCultureIgnoreCase
3334
};
3435

3536
try
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
Markup,InShops,ProductName
2-
39150.0,2/01/1985 12:00:00 AM,mouse trap
3-
270.060,23/05/2008 12:00:00 AM,moonbuggy
4-
6004.0,29/02/2004 12:00:00 AM,dog house
2+
39150.0,1/2/1985 12:00:00 AM,mouse trap
3+
270.060,5/23/2008 12:00:00 AM,moonbuggy
4+
6004.0,2/29/2004 12:00:00 AM,dog house
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)