From 2a1cd4fda8a4a8e649910d16b4dfa1ce7ae63543 Mon Sep 17 00:00:00 2001 From: chai <215380520@qq.com> Date: Fri, 12 May 2023 09:24:40 +0800 Subject: *misc --- .../examples/configuration/attributes/index.md | 49 ++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper.Website/input/examples/configuration/attributes/index.md (limited to 'ThirdParty/CsvHelper-master/src/CsvHelper.Website/input/examples/configuration/attributes/index.md') 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().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; } +} + +``` -- cgit v1.1-26-g67d0