Class property value copier (Mapper) - copy property values from one class to another
It would be beneficial to be able to copy matching properties from one class to another instead of manually writing out individual assignments
For example; to copy the matching properties from PersonName to Person ignoring unmatched properties:
public class Person() {
public string LastName { get; set; }
public string FirstName { get; set; }
public string JobTitle { get; set; }
}
public class PersonName() {
public string LastName { get; set; }
public string FirstName { get; set; }
public string Middle Initial { get; set; }
}
Instead of this:
person.LastName = personName.LastName;
person.FirstName = personName.FirstName;
Would be nice to be able to do something like this:
If Object.TryCopyProperties(person, personName) …
Or an extension method:
person.CopyPropertiesFrom(personName)
