Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static bool PropertiesEqual<T>(T self, T to, Dictionary<string, Tuple<object, object>> differences, params string[] ignore) where T : class
- {
- if (self != null && to != null)
- {
- Type type = typeof(T);
- List<string> ignoreList = new List<string>(ignore);
- foreach (System.Reflection.PropertyInfo pi in type.GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance))
- {
- if (!ignoreList.Contains(pi.Name))
- {
- object selfValue = type.GetProperty(pi.Name).GetValue(self, null);
- object toValue = type.GetProperty(pi.Name).GetValue(to, null);
- if (selfValue != toValue && (selfValue == null || !selfValue.Equals(toValue)))
- {
- differences[pi.Name] = new Tuple<object, object>(selfValue, toValue);
- continue;
- }
- }
- }
- return differences.Count == 0;
- }
- return self == to;
- }
Advertisement
Add Comment
Please, Sign In to add comment