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 --- .../class-maps/mapping-by-index/index.html | 465 +++++++++++++++++++++ 1 file changed, 465 insertions(+) create mode 100644 ThirdParty/CsvHelper-master/docs/examples/configuration/class-maps/mapping-by-index/index.html (limited to 'ThirdParty/CsvHelper-master/docs/examples/configuration/class-maps/mapping-by-index/index.html') diff --git a/ThirdParty/CsvHelper-master/docs/examples/configuration/class-maps/mapping-by-index/index.html b/ThirdParty/CsvHelper-master/docs/examples/configuration/class-maps/mapping-by-index/index.html new file mode 100644 index 0000000..9aa7759 --- /dev/null +++ b/ThirdParty/CsvHelper-master/docs/examples/configuration/class-maps/mapping-by-index/index.html @@ -0,0 +1,465 @@ + + + + + + + + + + + + + + + + + + + + + + + Mapping By Index | CsvHelper + + + + + + + + + + + + + + + + +
+
+
+ + + +
+
+
+

Mapping by Index

+

If your data doesn't have a header you can map by index instead of name. You can't rely on the order of class properties in .NET, so if you're not mapping by name, make sure you specify an index.

+
Data
+
1,one
+
+
Example
+
void Main()
+{
+    var config = new CsvConfiguration(CultureInfo.InvariantCulture)
+    {
+        HasHeaderRecord = false,
+    };
+    using (var reader = new StreamReader("path\\to\\file.csv"))
+    using (var csv = new CsvReader(reader, config))
+    {
+        csv.Context.RegisterClassMap<FooMap>();
+        var records = csv.GetRecords<Foo>();
+    }
+}
+
+public class Foo
+{
+    public int Id { get; set; }
+    public string Name { get set; }
+}
+
+public sealed class FooMap : ClassMap<Foo>
+{
+    public FooMap()
+    {
+        Map(m => m.Id).Index(0);
+        Map(m => m.Name).Index(1);
+    }
+}
+
+ +
+
+
+
+ +

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