Exemplo n.º 1
0
        static ReportDto()
        {
            var config = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap <Report, ReportDto>()
                // Map inner ReportSettings to ReportSettingsDto
                .ForMember(
                    dto => dto.ReportSettings,
                    opt => opt.MapFrom(x => ReportSettingsDto.Wrap(x.ReportSettings)))
                // Map PropertyCollection to Dictionary<string, object>
                .ForMember(
                    dto => dto.Values,
                    opt => opt.MapFrom(
                        x => x.Values.ToDictionary(
                            t => t.Key.Name,
                            t => t.Value)));
                cfg.CreateMap <ReportDto, Report>()
                // Map ReportSettingsDto to ReportSettings
                .ForMember(
                    bo => bo.ReportSettings,
                    opt => opt.MapFrom(x => ReportSettingsDto.Unwrap(x.ReportSettings)))
                // Map Dictionary<string, object> to PropertyCollection
                .ForMember(
                    bo => bo.Values,
                    opt => opt.MapFrom(
                        x => new PropertiesCollection(
                            x.Values.Select(selector => new KeyValuePair <Property, object>(
                                                DynamicPropertyManagers.Reports.GetProperty(selector.Key),
                                                selector.Value)))));
            });

            MapperInstance = config.CreateMapper();
        }
Exemplo n.º 2
0
 public static ReportSettings Unwrap(ReportSettingsDto reportSettingsDto)
 {
     return(MapperInstance.Map <ReportSettings>(reportSettingsDto));
 }