There must be an easier way…
void TransferFrom(object obj) {
foreach(PropertyInfo prop in this.GetType().GetProperties()) {
prop.SetValue(this, obj.GetType().GetProperty(prop.Name).GetValue(obj, null), null);
}
}
I have two separate libraries with the same object definition – all property names/types are the same. Is the above the only way to copy the values or is there another way? I’m unable to reference one of the dlls and the object to be copied is passed as an object rather than a distinct type.
If you have control over both assemblies, take a look at Data Contracts, which were designed specifically to do what you’re describing.