C# — Serializing list of objects to csv
Serializing list of objects to csv with minimal code using reflection.
Aug 23, 2017 · 2 min read
We will start by defining a generic method where T could be any class.
public void GenerateReport<T>(List<T> rows) where T : class
{}
Now parse the properties of T, simply define what properties you want to include in the where linq clause. In this example I’m only selecting properties with PropertyType string, bool, char, byte, decimal, int, DateTime or DateTime?.
