Esempio n. 1
0
        public void Example()
        {
            Mapper.Initialize(cfg =>
            {
                cfg.CreateMap<ContainsASrc, ContainsADest>();

                cfg.CreateMap<ASrc, ADest>()
                    .Include<BSrc, BDest>()
                    .Include<CSrc, CDest>();

                cfg.CreateMap<BSrc, BDest>()
                    .Include<CSrc, CDest>();

                cfg.CreateMap<CSrc, CDest>();
            });

            var expectedCSrc = new CSrc() {StringA = "A", StringB = "B", StringC = "C"};
            var expectedBSrc = new BSrc() {StringA = "A", StringB = "B"};

            var expectedContCSrc = new ContainsASrc() {A = expectedCSrc};
            var expectedContBSrc = new ContainsASrc() {A = expectedBSrc};

            var actualContCDest = Mapper.Map<ContainsASrc, ContainsADest>(expectedContCSrc);
            var actualContBDest = Mapper.Map<ContainsASrc, ContainsADest>(expectedContBSrc); // THROWS

            Mapper.AssertConfigurationIsValid();
            actualContBDest.ShouldNotBeNull();
            actualContCDest.ShouldNotBeNull();
        }
Esempio n. 2
0
        public void Example()
        {
            Mapper.Initialize(cfg =>
            {
                cfg.CreateMap <ContainsASrc, ContainsADest>();

                cfg.CreateMap <ASrc, ADest>()
                .Include <BSrc, BDest>()
                .Include <CSrc, CDest>();

                cfg.CreateMap <BSrc, BDest>()
                .Include <CSrc, CDest>();

                cfg.CreateMap <CSrc, CDest>();
            });

            var expectedCSrc = new CSrc()
            {
                StringA = "A", StringB = "B", StringC = "C"
            };
            var expectedBSrc = new BSrc()
            {
                StringA = "A", StringB = "B"
            };

            var expectedContCSrc = new ContainsASrc()
            {
                A = expectedCSrc
            };
            var expectedContBSrc = new ContainsASrc()
            {
                A = expectedBSrc
            };

            var actualContCDest = Mapper.Map <ContainsASrc, ContainsADest>(expectedContCSrc);
            var actualContBDest = Mapper.Map <ContainsASrc, ContainsADest>(expectedContBSrc); // THROWS

            Mapper.AssertConfigurationIsValid();
            actualContBDest.ShouldNotBeNull();
            actualContCDest.ShouldNotBeNull();
        }