Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 150897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T09:21:49+00:00 2026-05-11T09:21:49+00:00

I want to compare two objects of different versions and display their differences in

  • 0

I want to compare two objects of different versions and display their differences in UI.

First I call a method to know if there is any difference between the two objects

The method is:

public bool AreEqual(object object1,object object2, Type comparisionType) 

If the above method returns true, I call the GetDifferences method to get the differences which is:

public ObjectDifference[] GetObjectDifferences(object object1, object object2, Type comparisionType) {   ArrayList memberList = new ArrayList();   ArrayList differences = new ArrayList();    memberList.AddRange(comparisionType.GetProperties());   memberList.AddRange(comparisionType.GetFields());    for (int loopCount = 0; loopCount < memberList.Count; loopCount++)   {     object objVal1 = null;     object objVal2 = null;     MemberInfo member = ((MemberInfo)memberList[loopCount]);     switch (((MemberInfo)memberList[loopCount]).MemberType)     {       case MemberTypes.Field:         objVal1 = object1 != null ? ((FieldInfo)memberList[loopCount]).GetValue(object1) : null;         objVal2 = object2 != null ? ((FieldInfo)memberList[loopCount]).GetValue(object2) : null;         break;       case MemberTypes.Property:          objVal1 = object1 != null ? ((PropertyInfo)memberList[loopCount]).GetValue(object1, null) : null;         objVal2 = object2 != null ? ((PropertyInfo)memberList[loopCount]).GetValue(object2, null) : null;         break;       default:         break;     }      if (AreValuesDifferentForNull(objVal1, objVal2))     {       ObjectDifference obj = new ObjectDifference(objVal1, objVal2, member, member.Name);       differences.Add(obj);     }     else if (AreValuesDifferentForPrimitives(objVal1, objVal2))     {       ObjectDifference obj = new ObjectDifference(objVal1, objVal2, member, member.Name);       differences.Add(obj);     }     else if (AreValuesDifferentForList(objVal1, objVal2))     {       ObjectDifference[] listDifference = GetListDifferences((ICollection)objVal1, (ICollection)objVal2, member);       differences.AddRange(listDifference);     }     else if ((!AreValuesEqual(objVal1, objVal2)) && (objVal1 != null || objVal2 != null))     {       ObjectDifference obj = new ObjectDifference(objVal1, objVal2, member, member.Name);       differences.Add(obj);     }   }   return (ObjectDifference[])differences.ToArray(typeof(ObjectDifference)); }   public class ObjectDifference {   private readonly object objectValue1;   private readonly object objectValue2;   private readonly System.Reflection.MemberInfo member;   private readonly string description;    public object ObjectValue1   {     get { return objectValue1; }   }   public object ObjectValue2   {     get { return objectValue2; }   }   public System.Reflection.MemberInfo Member   {     get { return member; }   }   public string Description   {     get { return description; }   }    public ObjectDifference(object objVal1, object objVal2, System.Reflection.MemberInfo member, string description)   {     this.objectValue1 = objVal1;     this.objectValue2 = objVal2;     this.member = member;     this.description = description;   } } 

For each difference I create an object of type ObjectDifference and add it to the array. The highlighted portion is the one where I am stuck! If the object contains another complex object, My program does give me the differences but I dont know which type it belonged to

For example, I have two objects of type Name

class Name {   string firstName, LastName;   List phNumber; }  class PhoneNumber {   string officeNo, MobileNo, HomeNo; } 

while comparing two objects the output I get is plain –

  • firstname – John Mary
  • LastName – cooper Lor
  • officeNo – 22222 44444
  • MobileNo – 989898 089089
  • HomeNo – 4242 43535

The Hierarchy that officeNo is of type PhoneNumber is lost, which is important for me to display.

How should I maintain this type of tree while creating differences? Hope I am able to make my problem understood.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T09:21:49+00:00Added an answer on May 11, 2026 at 9:21 am

    What you are trying to do and display is inherently complex. I’ve done this in the past (for diffgram/delta-based processes), and even trying to display nested changes in a simple and friendly way is tricky.

    If it fits your user-base, one option might be to simply serialize the two graphs as xml, and use something like xml diff.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to know the best way to compare two objects and to find
I want to write a function that accepts two objects as parameters and compare
I have two arrays of System.Data.DataRow objects which I want to compare. The rows
I want to compare and contrast the various source control systems out there. Any
I want to compare two ms-access .mdb files to check that the data they
can i somehow compare two numbers in regex? i want regex that is correct
When I implement objects that I want to compare using the IEquatable<T> interface :
I want to compare C++ class/structure objects. In C, most of the time, one
More specifically I want an interface to compare objects which can be only compared
I want to compare the current value of an in-memory Hibernate entity with the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.