-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathPropertyComparer - FFx.cs
49 lines (40 loc) · 1.12 KB
/
PropertyComparer - FFx.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
#if !PCL
namespace OpenNETCF
{
public class PropertyComparer<T> : IEqualityComparer<T>
{
public bool Equals(T x, T y)
{
return Equals(x, y, false);
}
public bool Equals(object x, object y, bool compareNonPublicProperties)
{
var type = x.GetType();
if (!type.Equals(y.GetType())) return false;
var flags = BindingFlags.Instance | BindingFlags.Public;
if(compareNonPublicProperties)
{
flags |= BindingFlags.NonPublic;
}
var props = type.GetProperties(flags);
foreach (var prop in props)
{
if (!prop.CanRead) continue;
var a = prop.GetValue(x, null);
var b = prop.GetValue(y, null);
if (!a.Equals(b)) return false;
}
return true;
}
public int GetHashCode(T obj)
{
return obj.GetHashCode();
}
}
}
#endif