-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathDelimitedFieldSettingsConstructor.cs
More file actions
61 lines (51 loc) · 2.11 KB
/
Copy pathDelimitedFieldSettingsConstructor.cs
File metadata and controls
61 lines (51 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
namespace FlatFile.Delimited.Implementation
{
using System;
using System.Reflection;
using FlatFile.Core;
using FlatFile.Core.Extensions;
public class DelimitedFieldSettingsConstructor :
DelimitedFieldSettings,
IDelimitedFieldSettingsConstructor
{
public DelimitedFieldSettingsConstructor(PropertyInfo propertyInfo) : base(propertyInfo)
{
}
public IDelimitedFieldSettingsConstructor AllowNull(string nullValue)
{
this.IsNullable = true;
this.NullValue = nullValue;
return this;
}
public IDelimitedFieldSettingsConstructor WithTypeConverter<TConverter>() where TConverter : ITypeConverter
{
this.TypeConverter = ReflectionHelper.CreateInstance<TConverter>(true);
return this;
}
public IDelimitedFieldSettingsConstructor WithConversionFromString<TProperty>(Func<string, TProperty> conversion)
{
if (TypeConverter == null)
TypeConverter = new DelegatingTypeConverter<TProperty>();
if (TypeConverter is DelegatingTypeConverter<TProperty>)
((DelegatingTypeConverter<TProperty>)TypeConverter).ConversionFromString = conversion;
else
throw new InvalidOperationException("A type converter has already been explicitly set.");
return this;
}
public IDelimitedFieldSettingsConstructor WithConversionToString<TProperty>(Func<TProperty, string> conversion)
{
if (TypeConverter == null)
TypeConverter = new DelegatingTypeConverter<TProperty>();
if (TypeConverter is DelegatingTypeConverter<TProperty>)
((DelegatingTypeConverter<TProperty>)TypeConverter).ConversionToString = conversion;
else
throw new InvalidOperationException("A type converter has already been explicitly set.");
return this;
}
public IDelimitedFieldSettingsConstructor WithName(string name)
{
Name = name;
return this;
}
}
}