diff options
Diffstat (limited to 'ThirdParty/CsvHelper-master/src/CsvHelper.Website/input/examples/configuration/attributes/index.md')
-rw-r--r-- | ThirdParty/CsvHelper-master/src/CsvHelper.Website/input/examples/configuration/attributes/index.md | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper.Website/input/examples/configuration/attributes/index.md b/ThirdParty/CsvHelper-master/src/CsvHelper.Website/input/examples/configuration/attributes/index.md new file mode 100644 index 0000000..871798f --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper.Website/input/examples/configuration/attributes/index.md @@ -0,0 +1,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; } +} + +``` |