将2个数组映射到对象列表,每个数组作为属性

时间:2017-08-16 10:16:01

标签: c# linq automapper

在kentico中,页面的类别保存在名为IInfoObjectCollection的对象中。奇怪的是,它将类别细节保存在单独的数组中,因此类别ID保存在Guids数组中,然后类别名称保存在此对象集合中的字符串数组中

我在kentico treenode中所拥有的类的示例:

public class InfoObjectCollection 
{
   public Guid[] CategoryIDs { get; set; }
   public string[] Names { get; set; }
}

现在我有一个类别类:

public class Category
{
   public Guid CategoryID { get; set; }
   public string Name { get; set; }
}

有没有办法使用automapper和linq(或不使用)将InfoObject映射到类别集合中?

1 个答案:

答案 0 :(得分:1)

上午看来有点矫枉过正

source.CategoryIDs.Zip(source.Names, (id, name)=>new Category { CategoryID = id, Name = name});