Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion LINQtoCSV/CsvFileDescription.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;

Expand Down Expand Up @@ -90,7 +91,12 @@ public int MaximumNbrExceptions
public bool UseFieldIndexForReadingData { get; set; }
public bool UseOutputFormatForParsingCsvValue { get; set; }
public bool IgnoreTrailingSeparatorChar { get; set; }


/// <summary>
/// Allows for override of the string comparison strategy
/// </summary>
public IEqualityComparer<string> ColumnEqualityComparer { get; set; }

/// <summary>
/// If set to true, wil read only the fields specified as attributes, and will discard other fields in the CSV file
/// </summary>
Expand Down
4 changes: 3 additions & 1 deletion LINQtoCSV/FieldMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,9 @@ public FieldMapper(CsvFileDescription fileDescription, string fileName, bool wri
m_fileDescription = fileDescription;
m_fileName = fileName;

m_NameToInfo = new Dictionary<string, TypeFieldInfo>();
m_NameToInfo = fileDescription.ColumnEqualityComparer != null ?
new Dictionary<string, TypeFieldInfo>(fileDescription.ColumnEqualityComparer) :
new Dictionary<string, TypeFieldInfo>();

AnalyzeType(
typeof(T),
Expand Down
2 changes: 1 addition & 1 deletion TestConsoleApplication/ProductData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion TestConsoleApplication/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions TestConsoleApplication/TestFiles/output_anon.csv
Original file line number Diff line number Diff line change
@@ -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
Binary file modified TestConsoleApplication/TestFiles/output_names_nl.csv
Binary file not shown.
Binary file modified TestConsoleApplication/TestFiles/output_newdata_names_nl.csv
Binary file not shown.