I would like to copy one object to another object, and the fields with the same names and type to be copied. Perhaps using reflections.
e.g.
object1.Name = object2.Name;
object1.Age = object2.Age;
However if object2.Address is not in object1 then it would be ignored and vis-versa.
I answered a similar question here. The difference is that you want the from and to to have different types and to match properties by name and by type. This is not too hard.
I haven’t tested this – but give it a shot
}
If you don’t like the extension method, you could just rewrite this to be public static void CopyPropertiesTo(object source, object dest);
this should let you do something like this: