Wednesday, April 20, 2011

Beyond Compare for Object Instances

Does anyone know of a tool or library in .net that can be used to compare object properties and sub-objects like beyond compare does for text files? What I am looking for is a way to show two instances of the same type and show colored coded differences between them and allow the user to copy values between the objects.

From stackoverflow
  • Just an idea: serialize your objects into XML and run a WinDiff or TortoiseSVN built-in diff-viewer.

    1. The export can be done (with [Serializalbe] objects) with XmlSerializer or DataContractSerializer:

      Person p1 = new Person("Zighetti", "Barbara", 101);
      FileStream writer = new FileStream(fileName, FileMode.Create);
      DataContractSerializer ser = new DataContractSerializer(typeof(Person));
      ser.WriteObject(writer, p1);
      writer.Close();
      
    2. Repeat this step for p2 (instance of Person).

    3. Drop your xmls into WinDiff or your favorite diff viewer.

    Special XML diff tools

    John Saunders : Yes, serialize it, but serialize to an XmlWriter configured to do indentation. You might also need to do postprocessing to maintain a canonical order.

0 comments:

Post a Comment

Note: Only a member of this blog may post a comment.