What is the algorithm used by the memberwise equality test in .NET structs? I would like to know this so that I can use it as the basis for my own algorithm.
I am trying
public static bool CompareMembers(this T source, T other, params Expression>[] propertiesToSkip)
{
PropertyInfo[] sourceProperties = source.GetType().GetProperties();
List propertiesToSkipList = (from x in propertiesToSkip
let a = x.Body as MemberExpression
let b = x.Body as UnaryExpression
select a == null ? ((MemberExpression)b.Operand).Member.Name : a.Member.Name).ToList();
List lstProperties = (
from propertyToSkip in propertiesToSkipList
from property in sourceProperties
where property.Name != propertyToSkip
select property).ToList();
return (!(lstProperties.Any(property => !property.GetValue(source, null).Equals(property.GetValue(other, null)))));
}
How to use:
bool test = myObj1.MemberwiseEqual(myObj2,
() => myObj.Id,
() => myObj.Name);