Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void MergeWith<T>(this T primary, T secondary)
- {
- foreach (var pi in typeof(T).GetProperties())
- {
- var priValue = pi.GetGetMethod().Invoke(primary, null);
- var secValue = pi.GetGetMethod().Invoke(secondary, null);
- bool bnullable = false;
- if (typeof(T).IsGenericType && typeof(T).GetGenericTypeDefinition() == typeof(Nullable<>))
- bnullable = true;
- if (((bnullable && secValue != null) == false) && !priValue.Equals(secValue))
- {
- pi.GetSetMethod().Invoke(primary, new object[] { secValue });
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement