Created
May 12, 2014 17:25
-
-
Save azhtom/3ce75899bad2ee2ce1bf to your computer and use it in GitHub Desktop.
Merge Two objetcs c#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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