Skip to content
Open
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
1 change: 1 addition & 0 deletions LINQtoCSV/CsvColumnAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class CsvColumnAttribute : System.Attribute
public NumberStyles NumberStyle { get; set; }
public string OutputFormat { get; set; }
public int CharLength { get; set; }
public string RegexPattern { get; set; }

public CsvColumnAttribute()
{
Expand Down
10 changes: 9 additions & 1 deletion LINQtoCSV/FieldMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;

namespace LINQtoCSV
{
Expand Down Expand Up @@ -32,6 +33,7 @@ protected class TypeFieldInfo : IComparable<TypeFieldInfo>
public MethodInfo parseNumberMethod = null;
public MethodInfo parseExactMethod;
public int charLength = 0;
public string RegexPattern { get; set; }

// ----

Expand Down Expand Up @@ -131,7 +133,7 @@ private TypeFieldInfo AnalyzeTypeField(
{
tfi.name = cca.Name;
}

tfi.RegexPattern = cca.RegexPattern;
tfi.index = cca.FieldIndex;
tfi.hasColumnAttribute = true;
tfi.canBeNull = cca.CanBeNull;
Expand Down Expand Up @@ -545,6 +547,12 @@ public T ReadObject(IDataRow row, AggregatedException ae) {
{
try
{
if (tfi.RegexPattern != null && !Regex.IsMatch(value, tfi.RegexPattern))
{
throw new WrongDataFormatException(typeof(T).ToString(), tfi.name, value, row[i].LineNbr, m_fileName, null);
}


Object objValue = null;

// Normally, either tfi.typeConverter is not null,
Expand Down