123456789101112131415161718192021222324252627282930 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Reflection;
- namespace HyperCube
- {
- public static class Compare
- {
- public static Dictionary<string, PropertyInfo> SimpleCompare<T>(T object1, T object2)
- {
- var props = typeof(T).GetProperties().Where(pi => pi.CanRead);
- Dictionary<string, PropertyInfo> result = new();
- foreach (var prop in props)
- {
- var val1 = prop.GetValue(object1, null);
- var val2 = prop.GetValue(object2, null);
- if (prop.PropertyType == typeof(DateTime))
- {
- TimeSpan timeSpan = (DateTime)val1 - (DateTime)val2;
- if (timeSpan.TotalDays != 0)
- result[prop.Name] = prop;
- }
- else if (val1?.ToString() != val2?.ToString())
- result[prop.Name] = prop;
- }
- return result;
- }
- }
- }
|