我有两个班级:
public class Customer
{
public string FirstName { get; set; }
public string LastName { get; set; }
};
public class Customer_
{
public string FirstNam { get; set; }
public string LastNam { get; set; }
}
我的班级Customer
的一个实例:
Customer[] Customer = new Customer[]
{
new Customer()
{
FirstName = "FirstName1",
LastName = "LastName1"
},
new Customer()
{
FirstName = "FirstName2",
LastName = "LastName2"
}
};
我想将我的对象Customer映射到我的对象Customer _的实例。
我使用Automapper:
var config = new MapperConfiguration(cfg =>
{
cfg.CreateMap<Customer, Customer_>();
});
IMapper mapper = config.CreateMapper();
var dest = mapper.Map<Customer[], Customer_[]>(Customer);
但是对象dest
有两个索引null
如何创建地图并定义映射?例如:Customer.FirstName = Customer_.FirstName ... etc
编辑:
我在Customer类中添加了一个新属性Quantity
(类型为int),并在我的实例中添加了一个值。现在,我想只映射数量> gt的客户X
Customer[] Customer = new Customer[]
{
new Customer()
{
FirstName = "FirstName1",
LastName = "LastName1",
Quantity = 11
},
new Customer()
{
FirstName = "FirstName2",
LastName = "LastName2",
Quantity = 5
}
};
怎么做?
答案 0 :(得分:1)
documentation相当清楚地概述了这一点。
因为目标属性的名称与源属性的名称不完全匹配,所以我们需要在类型映射配置中指定自定义成员映射:
plt.imshow(X[2:],cmap =plt.cm.gray_r, interpolation = "nearest")
请注意,如有必要,您必须在其他方向明确映射。