// Automapper configuration private static MapperConfiguration CreateMapperConfiguration(string mappingFolder) { var config = new MapperConfiguration(cfg => { if (!string.IsNullOrEmpty(mappingFolder)) { mappingFolder = mappingFolder + "\\"; } string configFile = $@"{mappingFolder}{typeof(MappedObjectType).Name}.mapping"; ConfigurableMapping <MappedObjectType> mapping = LoadMapping(configFile); cfg.AddProfiles(new Profile[] { mapping }); }); return(config); }
private static ConfigurableMapping <MappedObjectType> LoadMapping(string configFile) { IniData configFileData; try { FileIniDataParser parser = new FileIniDataParser(); configFileData = parser.ReadFile(configFile); } catch (ParsingException parsingException) { throw new ExcelToObjectException($@"Error parsing mapping file {configFile}: {parsingException.Message}"); } SectionData section = GetSection(configFileData); IList <MappedField> fields = GetFields(section); ConfigurableMapping <MappedObjectType> mapping = new ConfigurableMapping <MappedObjectType>(section.SectionName, fields); return(mapping); }