pushrbx icon

MergeWith function

pushrbx | PRO | 08/18/13 03:13:24 AM UTC | 0 ⭐ | 398 👁️ | Never ⏰ | []
C# |

600 B

|

None

|

0 👍

/

0 👎

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 });
        }
    }
}

Comments