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-duplicate-names/index.md | 41 ++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper.Website/input/examples/configuration/class-maps/mapping-duplicate-names/index.md (limited to 'ThirdParty/CsvHelper-master/src/CsvHelper.Website/input/examples/configuration/class-maps/mapping-duplicate-names/index.md') diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper.Website/input/examples/configuration/class-maps/mapping-duplicate-names/index.md b/ThirdParty/CsvHelper-master/src/CsvHelper.Website/input/examples/configuration/class-maps/mapping-duplicate-names/index.md new file mode 100644 index 0000000..47d44cc --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper.Website/input/examples/configuration/class-maps/mapping-duplicate-names/index.md @@ -0,0 +1,41 @@ +# Mapping Duplicate Names + +Sometimes you have duplicate header names. This is handled through a header name index. The name index is the index of how many occurrences of that header name there are, not the position of the header. + +###### Data + +``` +Id,Name,Name +1,first,last +``` + +###### Example + +```cs +void Main() +{ + using (var reader = new StreamReader("path\\to\\file.csv")) + using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture)) + { + csv.Context.RegisterClassMap(); + var records = csv.GetRecords(); + } +} + +public class Foo +{ + public int Id { get; set; } + public string FirstName { get set; } + public string LastName { get; set; } +} + +public sealed class FooMap : ClassMap +{ + public FooMap() + { + Map(m => m.Id); + Map(m => m.FirstName).Name("Name").NameIndex(0); + Map(m => m.LastName).Name("Name").NameIndex(1); + } +} +``` -- cgit v1.1-26-g67d0