/// <summary> | |
/// Copy every matching property from source -> target | |
/// </summary> | |
/// <param name="target"></param> | |
/// <param name="source"></param> | |
public static void Slurp(this object target, object source) | |
{ | |
target.GetType() | |
.GetProperties() | |
.Where(p => p.SetMethod != null) | |
.ToList() | |
.ForEach(p => | |
{ | |
var ps = source.GetType().GetProperty(p.Name); | |
if (ps != null && ps.GetMethod!=null) | |
{ | |
p.SetValue(target, ps.GetValue(source)); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment