summaryrefslogtreecommitdiff
path: root/ThirdParty/CsvHelper-master/src/CsvHelper.Website/input/examples/configuration/attributes/index.md
blob: 871798f14b2dff13fcd0f251d4bd0fc143b48306 (plain)
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
# Attributes

Most of the configuration done via class maps can also be done using attributes.

###### Data

```
Identifier,name,IsBool,Constant
1,one,yes,a
2,two,no,b
```

###### Example

```cs
void Main()
{
	using (var reader = new StreamReader("path\\to\\file.csv"))
	using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture))
	{
		csv.GetRecords<Foo>().ToList().Dump();
	}
}

[Delimiter(",")]
[CultureInfo("")]  // Set CultureInfo to InvariantCulture
public class Foo
{
	[Name("Identifier")]
	public int Id { get; set; }
	
	[Index(1)]
	public string Name { get; set; }
	
	[BooleanTrueValues("yes")]
	[BooleanFalseValues("no")]
	public bool IsBool { get; set; }
	
	[Constant("bar")]
	public string Constant { get; set; }
	
	[Optional]
	public string Optional { get; set; }
	
	[Ignore]
	public string Ignored { get; set; }	
}

```