Created
January 19, 2018 07:35
-
-
Save JoshClose/3797c4ef72e392f714a1125cf39607bd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Main() | |
{ | |
using (var stream = new MemoryStream()) | |
using (var writer = new StreamWriter(stream)) | |
using (var reader = new StreamReader(stream)) | |
using (var csv = new CsvReader(reader)) | |
{ | |
writer.WriteLine("Id,,Name"); | |
writer.WriteLine("1,,one"); | |
writer.WriteLine("2,,two"); | |
writer.Flush(); | |
stream.Position = 0; | |
csv.Configuration.RegisterClassMap<TestMap>(); | |
csv.Read(); | |
for (var i = 0; i < csv.Context.Record.Length; i++) | |
{ | |
csv.Context.Record[i] = csv.Context.Record[i] + i; | |
} | |
csv.ReadHeader(); | |
csv.GetRecords<Test>().ToList().Dump(); | |
} | |
} | |
public class Test | |
{ | |
public int Id { get; set; } | |
public string Name { get; set; } | |
} | |
public sealed class TestMap : ClassMap<Test> | |
{ | |
public TestMap() | |
{ | |
Map(m => m.Id).Name("Id0"); | |
Map(m => m.Name).Name("Name2"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment