我有两个班级:
public class A{
[System.Xml.Serialization.XmlElementAttribute("type1", typeof(XMLItemType1), IsNullable=true)]
[System.Xml.Serialization.XmlElementAttribute("type2", typeof(XMLItemType2), IsNullable=true)]
public object Item { get; set; }
}
public class B{
public object Item { get; set; }
}
映射创建如下:
AutoMapper.Mapper.CreateMap<A, B>()
.ForMember(domainObject => domainObject.Item ,
metaData => metaData.MapFrom(xmlObject => xmlObject.Item ));
AutoMapper.Mapper.CreateMap<XMLItemType1, XMLObjectType1>();
AutoMapper.Mapper.CreateMap<XMLItemType2, XMLObjectType2>();
AutoMapper.Mapper.Map<A, B>(data);
但是B类Item
的输出属性是XMLItemType1
类型,而不是XMLObjectType1
。
如何确保映射Item
的类型为XMLObjectType1
或XMLObjectType2
后?