I have two objects from this class:
public class A
{
public int Id { get; set; }
public string Name { get; set; }
public IList<B> Bs { get; set; }
}
public class B
{
public string Description { get; set; }
public IList<C> Cs { get; set; }
}
public class C
{
public string Description { get; set; }
}
Now I want to loop through all the properties of the two object instances with FastMember and copy the properties from object 1
to object 2
.
Here's what I got so far (not working!)
// Set accessors
var sourceAccessor = ObjectAccessor.Create(object1);
var targetAccessor = ObjectAccessor.Create(object2);
foreach (var sourceItem in (IList)sourceAccessor.Target)
{
var targetItemAccessor = ObjectAccessor.Create(targetAccessor.Target);
var sourceItemAccessor = ObjectAccessor.Create(sourceItem);
// Overwrite property
targetItemAccessor[p] = sourceItemAccessor[p];
}
this code is obviously not working...any ideas? Thanks!