Skip to content

Instantly share code, notes, and snippets.

@azhtom
Created May 12, 2014 17:25
Show Gist options
  • Save azhtom/3ce75899bad2ee2ce1bf to your computer and use it in GitHub Desktop.
Save azhtom/3ce75899bad2ee2ce1bf to your computer and use it in GitHub Desktop.
Merge Two objetcs c#
public void CopyValues<T>(T target, T source)
{
Type t = typeof(T);
var properties = t.GetProperties().Where(prop => prop.CanRead && prop.CanWrite);
foreach (var prop in properties)
{
var value = prop.GetValue(source, null);
if (value != null)
prop.SetValue(target, value, null);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment