Start by ditching the LINQ stuff. Rewrite in normal statements so you can debug what's going on. Here's a start:
public static bool PublicInstancePropertiesEqual<t>(this T self, T to, params string[] ignore) where T : class
{
if (self != null && to != null)
{
var type = typeof(T);
var ignoreList = new List<string>(ignore);
var typeProperties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
foreach (var pi in typeProperties)
{
var property = type.GetProperty(pi.Name);
var selfValue = property.GetValue(self);
var toValue = property.GetValue(to);
if (selfValue != toValue)
return false;
}
return true;
}
return false;
}</string></t>
Also, you've written an extension so you don't need to specify the
Compare....
to use it. All you need to do is:
bool result = x.PublicInstancePropertiesEqual(y, ignoreList);