我有一组来自datasource(VSO)的嵌套类,我想映射到合同。映射点是下一个:
为什么我要这个?:
问题:
不幸的是,我几乎没有使用Automapper的经验,如果不可能,那么我不想花时间使用它。如果是这样,那么我认为,CustomValueResolve将成为我的朋友。
来源:
public class Class1ToBeMapped
{
public string AreaPath = "Level1";
public List<Class1ToBeMapped> Children = new List<Class1ToBeMapped>()
{
{new Class1ToBeMapped()
{
AreaPath = "Level21",
Children = new List<Class1ToBeMapped>(){}
}},
{new Class1ToBeMapped()
{
AreaPath = "Level22",
Children = new List<Class1ToBeMapped>(){}
}}
};
}
映射对象,所需结果:
public class Class2Mapped
{
public string AreaPath = "Level1";
public string AreaPathFull = "Level1";
public List<Class2Mapped> Children = new List<Class2Mapped>()
{
{
new Class2Mapped()
{
AreaPath = "Level21",
AreaPathFull = "Level1/Level21",
Children = new List<Class2Mapped>()
{
{
new Class2Mapped()
{
AreaPath = "Level31",
AreaPathFull = "Level1/Level21/Level31",
Children = new List<Class2Mapped>()
{
{
new Class2Mapped()
{
AreaPath = "Level41",
AreaPathFull = "Level1/Level21/Level31/Level41",
Children = null
}
}
}
}
},
{
new Class2Mapped()
{
AreaPath = "Level22",
AreaPathFull = "Level1/Level22",
Children = new List<Class2Mapped>()
{
new Class2Mapped()
{
AreaPath = "Level32",
AreaPathFull = "Level1/Level22/Level32",
Children = null
}
}
}
}
}
},
}
};
}