summaryrefslogtreecommitdiff
path: root/ThirdParty/CsvHelper-master/src/CsvHelper.Website/input/examples/configuration/class-maps/mapping-properties/index.md
diff options
context:
space:
mode:
Diffstat (limited to 'ThirdParty/CsvHelper-master/src/CsvHelper.Website/input/examples/configuration/class-maps/mapping-properties/index.md')
-rw-r--r--ThirdParty/CsvHelper-master/src/CsvHelper.Website/input/examples/configuration/class-maps/mapping-properties/index.md39
1 files changed, 39 insertions, 0 deletions
diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper.Website/input/examples/configuration/class-maps/mapping-properties/index.md b/ThirdParty/CsvHelper-master/src/CsvHelper.Website/input/examples/configuration/class-maps/mapping-properties/index.md
new file mode 100644
index 0000000..a401b6d
--- /dev/null
+++ b/ThirdParty/CsvHelper-master/src/CsvHelper.Website/input/examples/configuration/class-maps/mapping-properties/index.md
@@ -0,0 +1,39 @@
+# Mapping Properties
+
+This will map the properties of a class to the header names of the CSV data. The mapping needs to be registered in the context. This example is identical to not using a class mapping at all. The headers match the property names.
+
+###### Data
+
+```
+Id,Name
+1,one
+```
+
+###### Example
+
+```cs
+void Main()
+{
+ using (var reader = new StreamReader("path\\to\\file.csv"))
+ using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture))
+ {
+ 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);
+ Map(m => m.Name);
+ }
+}
+```