快速解决以下代码不会发生映射的问题。有人可以解释为什么吗?或者我应该怎么做才能进行映射?
var parent = new Parent();
parent.ChildOne.Add(new ChildOne() { Name = "Child One" });
parent.ChildTwo.Add(new ChildTwo() { Name = "Child Two" });
AnotherParent anotherParent = new AnotherParent();
anotherParent.InjectFrom<LoopValueInjection>(parent);
必修课如下
另一个孩子一
public class AnotherChildOne
{
public string Name { get; set; }
}
另一个孩子二
public class AnotherChildTwo
{
public string Name { get; set; }
}
另一个家长
public class AnotherParent
{
public ICollection<AnotherChildOne> ChildOne { get; set; }
public ICollection<AnotherChildTwo> ChildTwo { get; set; }
public AnotherParent()
{
ChildOne = new Collection<AnotherChildOne>();
ChildTwo = new Collection<AnotherChildTwo>();
}
}
孩子二
public class ChildTwo
{
public string Name { get; set; }
}
孩子一
public class ChildOne
{
public string Name { get; set; }
}
家长
public class Parent
{
public ICollection<ChildOne> ChildOne { get; set; }
public ICollection<ChildTwo> ChildTwo { get; set; }
public Parent()
{
ChildOne = new Collection<ChildOne>();
ChildTwo = new Collection<ChildTwo>();
}
}