private IList <object> ReadSection(Type type, StatementData dataContainer, string section, IClassMapping classMapping) { IDictionary <string, string> fieldMapper = classMapping.FieldMappings; var tradeSections = dataContainer.GetSectionsByName(section); if (tradeSections == null || !tradeSections.Any()) { return(null); } IList <object> res = new List <object>(); foreach (var tradeSection in tradeSections) { Dictionary <string, int> fieldToIndex = new Dictionary <string, int>(); var lineIdx = 0; tradeSection.Lines.ForEach(tr => { if (tr.LineType != LineType.Data) { return; } var entity = Activator.CreateInstance(type); res.Add(entity); foreach (var field in fieldMapper.Keys) { if (!fieldToIndex.ContainsKey(field)) { var idx = tradeSection.Headers.IndexOf(field); fieldToIndex[field] = idx; } var val = ""; var index = fieldToIndex[field]; if (index >= 0) { val = tr.Fields[index]; } else { continue; } if (string.IsNullOrEmpty(val)) { continue; } var propertyName = fieldMapper[field]; var propInfo = type.GetProperty(propertyName); if (propInfo.PropertyType == typeof(string)) { propInfo.SetValue(entity, val); } else { if (val.CanChangeType(propInfo.PropertyType)) { object convertedValue = Convert.ChangeType(val, propInfo.PropertyType, CultureInfo.InvariantCulture); propInfo.SetValue(entity, convertedValue); } else { throw new TaxCalcException($"line: {lineIdx} - field {field} value cannot be set from {val}"); } } } lineIdx++; }); } res = classMapping.Filter != null?res?.Where(classMapping.Filter.Compile()).ToList() : res; return(res); }