AnyDiff 1.0.0

A CSharp library that allows you to diff two objects and get a list of the differences back.

There is a newer version of this package available.
See the version list below for details.
Install-Package AnyDiff -Version 1.0.0
dotnet add package AnyDiff --version 1.0.0
<PackageReference Include="AnyDiff" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add AnyDiff --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

AnyDiff

A CSharp library that allows you to diff two objects and get a list of the differences back.

Description

AnyDiff works with complex objects of any type, and is great for performing changeset tracking, auditing, or anything else that might require comparing differences between complex objects. Great when combined with AnyClone, as it lets you take a snapshot of the current state of an object and then compare it in the future for changes to it.

It can even do this for objects that are of different types, though the results may vary depending on how different they are.

Usage

Comparing two objects with no differences:

var object1 = new MyComplexObject(1, "A string");
var object2 = new MyComplexObject(1, "A string");
var diff = AnyDiff.Diff(object1, object2);
Assert.AreEqual(diff.Count, 0);

Comparing two objects with a single expected change:

var object1 = new MyComplexObject(1, "A string");
var object2 = new MyComplexObject(1, "A different string");
var diff = AnyDiff.Diff(object1, object2);
Assert.AreEqual(diff.Count, 1);

Viewing the results of a diff:

var diff = AnyDiff.Diff(object1, object2);
var diff = AnyDiff.Diff(object1, object2);

foreach(var difference in diff)
{
  Console.Write($"Index: {difference.ArrayIndex}"); // when array elements differ in value
  Console.Write($"Delta: {difference.Delta}"); // when numbers, strings differ in value
  Console.Write($"Left: {difference.LeftValue}"); // the left value being compared
  Console.Write($"Right: {difference.RightValue}"); // the right value being compared
  Console.Write($"Property name: {difference.Property}"); // the name of the field/property
  Console.Write($"Property type: {difference.PropertyType}"); // the type of the field/property
}

Comparing the difference between the same object at different states, using AnyClone

// using AnyClone;
var object1 = new MyComplexObject(1, "A string");
var object1Snapshot = object1.Clone();

var diff = AnyDiff.Diff(object1, object1Snapshot);
Assert.AreEqual(diff.Count, 0);

// change something anywhere in the object tree
object1.Name = "A different string";

diff = AnyDiff.Diff(object1, object1Snapshot);
Assert.AreEqual(diff.Count, 1);

AnyDiff

A CSharp library that allows you to diff two objects and get a list of the differences back.

Description

AnyDiff works with complex objects of any type, and is great for performing changeset tracking, auditing, or anything else that might require comparing differences between complex objects. Great when combined with AnyClone, as it lets you take a snapshot of the current state of an object and then compare it in the future for changes to it.

It can even do this for objects that are of different types, though the results may vary depending on how different they are.

Usage

Comparing two objects with no differences:

var object1 = new MyComplexObject(1, "A string");
var object2 = new MyComplexObject(1, "A string");
var diff = AnyDiff.Diff(object1, object2);
Assert.AreEqual(diff.Count, 0);

Comparing two objects with a single expected change:

var object1 = new MyComplexObject(1, "A string");
var object2 = new MyComplexObject(1, "A different string");
var diff = AnyDiff.Diff(object1, object2);
Assert.AreEqual(diff.Count, 1);

Viewing the results of a diff:

var diff = AnyDiff.Diff(object1, object2);
var diff = AnyDiff.Diff(object1, object2);

foreach(var difference in diff)
{
  Console.Write($"Index: {difference.ArrayIndex}"); // when array elements differ in value
  Console.Write($"Delta: {difference.Delta}"); // when numbers, strings differ in value
  Console.Write($"Left: {difference.LeftValue}"); // the left value being compared
  Console.Write($"Right: {difference.RightValue}"); // the right value being compared
  Console.Write($"Property name: {difference.Property}"); // the name of the field/property
  Console.Write($"Property type: {difference.PropertyType}"); // the type of the field/property
}

Comparing the difference between the same object at different states, using AnyClone

// using AnyClone;
var object1 = new MyComplexObject(1, "A string");
var object1Snapshot = object1.Clone();

var diff = AnyDiff.Diff(object1, object1Snapshot);
Assert.AreEqual(diff.Count, 0);

// change something anywhere in the object tree
object1.Name = "A different string";

diff = AnyDiff.Diff(object1, object1Snapshot);
Assert.AreEqual(diff.Count, 1);

Release Notes

A CSharp library that allows you to diff two objects and get a list of the differences back.

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.0.56 1,250 5/23/2019
1.0.55 429 5/22/2019
1.0.54 429 5/22/2019
1.0.52 431 5/22/2019
1.0.51 424 5/22/2019
1.0.50 432 5/21/2019
1.0.48 429 5/21/2019
1.0.47 435 5/16/2019
1.0.45 868 4/20/2019
1.0.38 2,042 1/11/2019
1.0.37 2,935 1/7/2019
1.0.34 504 12/28/2018
1.0.25 753 12/4/2018
1.0.23 471 12/2/2018
1.0.22 531 12/2/2018
1.0.20 1,068 12/2/2018
1.0.8 473 12/1/2018
1.0.7 496 11/30/2018
1.0.5 487 11/29/2018
1.0.4 526 11/28/2018
1.0.0 493 11/16/2018
Show less