Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/drupal/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 具有相同基类的不同类型的自动映射类_C#_Automapper 3 - Fatal编程技术网

C# 具有相同基类的不同类型的自动映射类

C# 具有相同基类的不同类型的自动映射类,c#,automapper-3,C#,Automapper 3,我知道这听起来像是重复的,但实际上我找不到关于特定主题的任何信息,所以请先阅读,然后再判断:-) 我想使用automapper从一个很大的类结构中复制信息,而我并没有控制它。接口和类不能由我更改 首先将此结构视为众所周知的工作模式: 资料来源: [DataMember] [原成员(4)] 公共列表行程=新列表(); 目的地: [XmlArray("Journeys")] [DataMember] [XmlArrayItem("InventoryJourney", typeof (Invento

我知道这听起来像是重复的,但实际上我找不到关于特定主题的任何信息,所以请先阅读,然后再判断:-)

我想使用automapper从一个很大的类结构中复制信息,而我并没有控制它。接口和类不能由我更改

首先将此结构视为众所周知的工作模式: 资料来源:

[DataMember]
[原成员(4)]
公共列表行程=新列表();
目的地:

[XmlArray("Journeys")]
[DataMember]
[XmlArrayItem("InventoryJourney", typeof (InventoryJourney), Namespace = "http://my.schema.com/msg.journey")]
public MsgList<InventoryJourney> Journeys
{
  get
  {
    if (this._journeys == (MsgList<InventoryJourney>) null)
      this._journeys = new MsgList<InventoryJourney>();
    return this._journeys;
  }
  set
  {
    this._journeys = value;
  }
}
public MsgList<Segment> Segments
[XmlArray(“旅程”)]
[数据成员]
[XmlArrayItem(“InventoryTourney”,typeof(InventoryTourney),命名空间=”http://my.schema.com/msg.journey")]
公共英语旅程
{
得到
{
if(this.\u行程==(MsgList)null)
这个。_travelies=new MsgList();
把这个还给我;
}
设置
{
这。_行程=值;
}
}
InventoryTourney是对Tourney类的直接继承。由于界面清楚地显示了要创建的类型,Automapper可以正确地处理这些类型。目标将包含InventoryTourney类型的对象

现在我的问题是:

提到的InventoryTourney类需要填充一个在基类Tourney中定义的属性,如下所示:

Mapper.CreateMap<Source.Segment, Destination.Segment>()
    .Include<Source.Segment, Destination.InventorySegment>();
Mapper.CreateMap<Source.Segment, Destination.InventorySegment>();
目的地:

[XmlArray("Journeys")]
[DataMember]
[XmlArrayItem("InventoryJourney", typeof (InventoryJourney), Namespace = "http://my.schema.com/msg.journey")]
public MsgList<InventoryJourney> Journeys
{
  get
  {
    if (this._journeys == (MsgList<InventoryJourney>) null)
      this._journeys = new MsgList<InventoryJourney>();
    return this._journeys;
  }
  set
  {
    this._journeys = value;
  }
}
public MsgList<Segment> Segments
公共MsgList段
资料来源:

public List<Segment> Segments = new List<Segment>();
公共列表段=新列表();
此属性的签名看起来像应该包含段类,但实际上此列表包含InventorySecgment类型的类,它是段类的直接继承

是否可以以创建特定派生类型而不是属性定义的基类型的方式配置AutoMapper

我当前的配置如下所示:

Mapper.CreateMap<Source.Segment, Destination.Segment>()
    .Include<Source.Segment, Destination.InventorySegment>();
Mapper.CreateMap<Source.Segment, Destination.InventorySegment>();
Mapper.CreateMap()
.Include();
CreateMap();