I am looking to find a way to take two objects that have identical properties, and make a call to copy property values from one object to another. In the example below, suppose I have an instance of A, and I want to use the data of this instance to hydrate a new instance or C (to keep something short, I used fields instead of properties in the example below)
public class A : B
{
public string prop1;
public int prop2;
}
public class B
{
public byte propX;
public float propY;
}
public class C
{
public byte propX;
public float propY;
public string prop1;
public int prop2;
}
public class Merger
{
public static object Merge(object copyFrom, object copyTo)
{
}
}
The merge class is just an example of psuedo, so doing this with generics will be optimal, but the first thing I ask is whether there is such a possibility. I could have imagined that I was doing it myself by reflection, but I just wanted to throw it away for the best ideas first.
: , MVVM, , EF, ViewModel.