Example #1
0
        private static void autoMapping()
        {
            Mapper.Initialize(cfg => cfg.CreateMap <MyObject, MyOtherObject>());
            MyOtherObject oo = Mapper.Map <MyOtherObject>(o);

            Console.WriteLine(oo.Name);
            Console.WriteLine(oo.Size);
            Console.WriteLine(oo.LName ?? "LName is null");
        }
Example #2
0
        private static void configMapping()
        {
            var config = new MapperConfiguration(cfg =>
                                                 cfg.CreateMap <MyObject, MyOtherObject>()
                                                 .ForMember(dest => dest.LName, opts => opts.MapFrom(source => source.LastName))
                                                 );

            var           mapper = config.CreateMapper();
            MyOtherObject oo     = mapper.Map <MyOtherObject>(o);

            Console.WriteLine(oo.Name);
            Console.WriteLine(oo.Size);
            Console.WriteLine(oo.LName ?? "LName is null");
        }