6ca41ed720
- eliminazione riferimenti codice escluso da compilazione - pulizia codice da componenti non impiegati NON ancora 100% ok pulizia
33 lines
1.4 KiB
C#
33 lines
1.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Egw.Core
|
|
{
|
|
public class Utils
|
|
{
|
|
/// <summary>
|
|
/// Effettua salvataggio in file di un generico oggetto in formato CSV
|
|
/// </summary>
|
|
/// <typeparam name="T"></typeparam>
|
|
/// <param name="reportData"></param>
|
|
/// <param name="path"></param>
|
|
/// <param name="separator">Separatore da impiegare</param>
|
|
/// <returns></returns>
|
|
public static async Task SaveToCsv<T>(List<T> reportData, string path, char separator)
|
|
{
|
|
var lines = new List<string>();
|
|
IEnumerable<PropertyDescriptor> props = TypeDescriptor.GetProperties(typeof(T)).OfType<PropertyDescriptor>();
|
|
var header = string.Join(";", props.ToList().Select(x => x.Name));
|
|
lines.Add(header);
|
|
var valueLines = reportData.Select(row => string.Join(separator, header.Split(separator).Select(a => row.GetType().GetProperty(a).GetValue(row, null))));
|
|
//var valueLines = reportData.Select(row => string.Join(";", header.Split(';').Select(a => row.GetType().GetProperty(a).GetValue(row, null))));
|
|
lines.AddRange(valueLines);
|
|
await Task.Run(() => File.WriteAllLines(path, lines.ToArray()));
|
|
}
|
|
}
|
|
}
|