Skip to content

Instantly share code, notes, and snippets.

@JoshClose
Created June 7, 2018 13:59
Show Gist options
  • Save JoshClose/03568bd5faabcab4d2d4d1111b69d0ca to your computer and use it in GitHub Desktop.
Save JoshClose/03568bd5faabcab4d2d4d1111b69d0ca to your computer and use it in GitHub Desktop.
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("X,Y,Z");
writer.WriteLine("1.23e-15,2.34e-15,3.45e-15");
writer.Flush();
stream.Position = 0;
csv.Configuration.RegisterClassMap<Point3DMap>();
csv.GetRecords<Point3D>().ToList().Dump();
}
}
public class Point3D
{
public decimal X { get; set; }
public decimal Y { get; set; }
public decimal Z { get; set; }
}
public class Point3DMap : ClassMap<Point3D>
{
public Point3DMap()
{
Map(m => m.X).Index(0).TypeConverterOption.NumberStyles(NumberStyles.Float);
Map(m => m.Y).Index(1).TypeConverterOption.NumberStyles(NumberStyles.Float);
Map(m => m.Z).Index(2).TypeConverterOption.NumberStyles(NumberStyles.Float);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment