Beispiel #1
0
        public string ConvertToCsv(IEnumerable <TEntity> entities)
        {
            var csv = new List <List <string> >();

            // export columns
            var type       = typeof(TEntity);
            var properties = type.GetProperties().Where(p => p.CanRead && p.CanWrite);

            var row = new List <string>();

            foreach (var property in properties)
            {
                row.Add(property.Name);
            }
            csv.Add(row);

            foreach (var entity in entities)
            {
                row = new List <string>();
                foreach (var property in properties)
                {
                    row.Add(property.GetValue(entity)?.ToString());
                }
                csv.Add(row);
            }
            return(CSVToListConveter.ConvertToCsv(csv));
        }
Beispiel #2
0
        public IEnumerable <TEntity> Read(string filePath, Encoding encoding = null)
        {
            var csv = CSVToListConveter.Read(filePath, encoding);

            return(ConvertToEntities(csv));
        }