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 --- .../configuration/class-maps/validation/index.html | 463 +++++++++++++++++++++ 1 file changed, 463 insertions(+) create mode 100644 ThirdParty/CsvHelper-master/docs/examples/configuration/class-maps/validation/index.html (limited to 'ThirdParty/CsvHelper-master/docs/examples/configuration/class-maps/validation/index.html') diff --git a/ThirdParty/CsvHelper-master/docs/examples/configuration/class-maps/validation/index.html b/ThirdParty/CsvHelper-master/docs/examples/configuration/class-maps/validation/index.html new file mode 100644 index 0000000..b97f314 --- /dev/null +++ b/ThirdParty/CsvHelper-master/docs/examples/configuration/class-maps/validation/index.html @@ -0,0 +1,463 @@ + + + + + + + + + + + + + + + + + + + + + + + Validation | CsvHelper + + + + + + + + + + + + + + + + +
+
+
+ + + +
+
+
+

Validation

+

If you want to ensure your data conforms to some sort of standard, you can validate it.

+
Data
+
Id,Name
+1,on-e
+
+
Example
+
void Main()
+{
+    using (var reader = new StreamReader("path\\to\\file.csv"))
+    using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture))
+    {
+        csv.Context.RegisterClassMap<FooMap>();
+        csv.GetRecords<Foo>().ToList().Dump();
+    }
+}
+
+public class Foo
+{
+    public int Id { get; set; }
+    public string Name { get; set; }
+    public DateTimeOffset? Date { get; set; }
+}
+
+public class FooMap : ClassMap<Foo>
+{
+    public FooMap()
+    {
+        Map(m => m.Id);
+        Map(m => m.Name).Validate(field => !field.Contains("-"));
+    }
+}
+
+ +
+
+
+
+ +

+ + + + + + + + + + + -- cgit v1.1-26-g67d0