<p>I would like to generate a list of differences between 2 instances of the the same object.  Object in question:</p>

<pre><code>public class Step
{
    [DataMember]
    public StepInstanceInfo InstanceInfo { get; set; }

    [DataMember]
    public Collection&lt;string&gt; AdHocRules { get; set; }

    [DataMember]
    public Collection&lt;StepDoc&gt; StepDocs
    {...}

    [DataMember]
    public Collection&lt;StepUsers&gt; StepUsers
    {...}
}
</code></pre>

<p>What I would like to do is <strong>find an intelligent way to return an object that lists the differences between the two instances</strong> (for example, let me know that 2 specific StepDocs were added, 1 specific StepUser was removed, and one rule was changed from "Go" to "Stop"). I have been looking into using a MD5 hash, but I can't find any good examples of traversing an object like this and returning a <strong>manifest of the specific differences</strong> (not just indicating that they are different).</p>

<p><em>Additional Background:</em> the reason that I need to do this is the API that I am supporting allows clients to SaveStep(Step step)...this works great for persisting the Step object to the db using entities and repositories.  I need to raise specific events (like this user was added, etc) from this SaveStep method, though, in order to alert another system (workflow engine) that a specific element in the step has changed.
Thank you.</p>

[{'answer_id': 56774, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': '<p>Implementing the IComparable interface in your object may provide you with the functionality you need.  This will provide you a custom way to determine differences between objects without resorting to checksums which really won\'t help you track what the differences are in usable terms.  Otherwise, there\'s no way to determine equality between two user objects in .NET that I know of.  There are some decent examples of the usage of this interface in the help file for Visual Studio, or <a href="https://learn.microsoft.com/en-us/dotnet/api/system.icomparable" rel="nofollow noreferrer">here</a>.  You might be able to glean some directives from the examples on clean ways to compare the properties and store the values in some usable manner for tracking purposes (perhaps a collection, or dictionary object?).  </p>\n\n<p>Hope this helps,\nGreg</p>\n'}, {'answer_id': 57832, 'author': 'Todd Rowan', 'author_id': 3473, 'author_profile': 'https://Stackoverflow.com/users/3473', 'pm_score': 3, 'selected': True, 'text': "<p>You'll need a separate object, like StepDiff with collections for removed and added items. The easiest way to do something like this is to copy the collections from each of the old and new objects, so that StepDiff has collectionOldStepDocs and collectionNewStepDocs. </p>\n\n<p>Grab the shorter collection and iterate through it and see if each StepDoc exists in the other collection. If so, delete the StepDoc reference from both collections. Then when you're finished iterating, collectionOldStepDocs contains stepDocs that were deleted and collectionNewStepDocs contains the stepDocs that were added. </p>\n\n<p>From there you should be able to build your manifest in whatever way necessary. </p>\n"}]
['https://Stackoverflow.com/questions/56698', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']