KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Given the following source types: public class BaseViewModel { public string Prop1 { get; set; } } public class FirstViewModelImpl : BaseViewModel { public string Prop2 { get; set; } } public class SecondViewModelImpl : BaseViewModel { public string AnotherProp { get; set; } } And the following destination types public class BaseDto { public string Prop1 { get; set; } } public class FirstDtoImpl : BaseDto { public string Prop2 { get; set; } } public class SecondDtoImpl : BaseViewModel { public string AnotherProp { get; set; } } With the following mappings: Mapper.CreateMap<FirstViewModelImpl,FirstDtoImpl>(); Mapper.CreateMap<SecondViewModelImpl,SecondDtoImpl>(); Can I do the following (trivial example) - given that I don't actually know the type of viewmodel until runtime? BaseViewModel myViewModel = GetAViewModelFromSomewhere(); FirstDtoImpl dto = (FirstDtoImpl)Mapper.Map<BaseViewModel,BaseDto>(myViewModel); I am trying this out now anyway!
Tags (comma-separated)
Save Edits
Cancel