forked from ServiceStack/ServiceStack.Text
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCsvConfig.cs
More file actions
56 lines (49 loc) · 1.28 KB
/
CsvConfig.cs
File metadata and controls
56 lines (49 loc) · 1.28 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
using System;
using System.Collections.Generic;
namespace ServiceStack.Text
{
public static class CsvConfig<T>
{
public static bool OmitHeaders { get; set; }
private static Dictionary<string, string> customHeadersMap;
public static Dictionary<string, string> CustomHeadersMap
{
get
{
return customHeadersMap;
}
set
{
customHeadersMap = value;
if (value == null) return;
CsvWriter<T>.ConfigureCustomHeaders(customHeadersMap);
}
}
public static object CustomHeaders
{
set
{
if (value == null) return;
if (value.GetType().IsValueType)
throw new ArgumentException("CustomHeaders is a ValueType");
var propertyInfos = value.GetType().GetProperties();
if (propertyInfos.Length == 0) return;
customHeadersMap = new Dictionary<string, string>();
foreach (var pi in propertyInfos)
{
var getMethod = pi.GetGetMethod();
if (getMethod == null) continue;
var oValue = getMethod.Invoke(value, new object[0]);
if (oValue == null) continue;
customHeadersMap[pi.Name] = oValue.ToString();
}
CsvWriter<T>.ConfigureCustomHeaders(customHeadersMap);
}
}
public static void Reset()
{
OmitHeaders = false;
CsvWriter<T>.Reset();
}
}
}