Пример #1
0
 public PersonViewModel MapWithIgnore(Person person)
 {
     Mapper.CreateMap<Person, PersonViewModel>()
         .ForMember(v => v.FullName, opt => opt.Ignore());
     Mapper.AssertConfigurationIsValid();
     return Mapper.Map<PersonViewModel>(person);
 }
Пример #2
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);
 }
Пример #3
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);
        }
Пример #4
0
 public PersonViewModel MapWithProfile(Person person)
 {
     Mapper.AddProfile<PersonProfile>();
     Mapper.AssertConfigurationIsValid();
     return Mapper.Map<PersonViewModel>(person);
 }