-
Notifications
You must be signed in to change notification settings - Fork 0
1. ExportData
emmateva18 edited this page Jul 14, 2021
·
3 revisions
-
IEnumerable<T>
list - string path
- string separator
First we get the data properties from a list.
var props = t.GetProperties();
This function creates a StringBuilder, in which we save first the column names separated by a delimiter
var names = props.Select(prop => prop.Name);
sb.AppendLine(string.Join(separator, names));
and then the data in the fields as string.
var values = props.Select(prop => { return prop.GetValue(item)?.ToString(); });
sb.AppendLine(string.Join(separator, values));
Then it saves everything in a file.
File.WriteAllText(path, sb.ToString());