예제 #1
0
 public PersonViewModel MapWithFullName(Person person)
 {
     Mapper.CreateMap<Person, PersonViewModel>()
         .ForMember(v => v.FullName,
                 opt => opt.MapFrom(m => string.Format("{0} {1}", m.FirstName, m.LastName)));
     Mapper.AssertConfigurationIsValid();
     var _viewModel = new PersonViewModel();
     Mapper.Map(person, _viewModel);
     return _viewModel;
     //return Mapper.Map<PersonViewModel>(person);
 }
예제 #2
0
        public PersonViewModel MapSimple(Person person, bool validate = false)
        {
            Mapper.CreateMap<Person, PersonViewModel>();
            if (validate)
                Mapper.AssertConfigurationIsValid();

            //方法1
            var _viewModel = new PersonViewModel();
            Mapper.Map(person, _viewModel);
            return _viewModel;

            //方法2
            //return Mapper.Map<PersonViewModel>(person);
        }