Let’s say you have to copy all the values of the properties of a class to another (maybe larger) class, but there’s no inheritance between them. You can achieve this using reflection very simply.
foreach (var prop in item.GetType().GetProperties()) { var p2 = outputModel.GetType().GetProperty(prop.Name); p2.SetValue(outputModel, prop.GetValue(item, null), null); }
Quick Links
Legal Stuff