Exemplo n.º 1
0
        /// <summary>
        /// Takes a <see cref="List{T}"/> of <see cref="Entity"/> objects and composes them into raw data
        /// using the specifications in the <see cref="MappingInfo"/>. This raw data can then be exported as a CSV file.
        /// This function is the opposite of <see cref="DataParser.ParseAsync{TEntityForSave}(IEnumerable{string[]}, MappingInfo, ImportErrors)"/>.
        /// </summary>
        public IEnumerable <string[]> Compose <TEntityForSave>(List <TEntityForSave> entities, MappingInfo mapping)
            where TEntityForSave : EntityWithKey
        {
            var result      = new List <string[]>(entities.Count); // it will be at least that long, so might as well
            int columnCount = mapping.ColumnCount();

            // Recursive function
            int numberOfRows = 0;

            foreach (var entity in entities)
            {
                numberOfRows += ComposeDataRowsFromEntity(entity, mapping, result, numberOfRows, columnCount);
            }

            return(result);
        }