Guest User

Untitled

a guest
May 21st, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. static bool Compare<T>(T Object1, T object2)
  2. {
  3. // Get the type of the object
  4. Type type = typeof(T);
  5.  
  6. // return false if any of the object is false
  7. if (object.Equals(Object1, default(T)) || object.Equals(object2, default(T)))
  8. {
  9. return false;
  10. }
  11.  
  12. // Loop through each properties inside class and get values for the property from both the objects and compare
  13. foreach (System.Reflection.PropertyInfo property in type.GetProperties())
  14. {
  15. if (property.Name != "ExtensionData")
  16. {
  17. string Object1Value = string.Empty;
  18. string Object2Value = string.Empty;
  19. if (type.GetProperty(property.Name).GetValue(Object1, null) != null)
  20. {
  21. Object1Value = type.GetProperty(property.Name).GetValue(Object1, null).ToString();
  22. }
  23.  
  24. if (type.GetProperty(property.Name).GetValue(object2, null) != null)
  25. {
  26. Object2Value = type.GetProperty(property.Name).GetValue(object2, null).ToString();
  27. }
  28.  
  29. if (Object1Value.Trim() != Object2Value.Trim())
  30. {
  31. return false;
  32. }
  33. }
  34. }
  35. return true;
  36. }
Add Comment
Please, Sign In to add comment