Skip to content

Objects of different type

Michael Brown edited this page Dec 2, 2018 · 1 revision

If you want to compare two objects of different types, that is supported. However, if the properties have different names they will show up as a difference. You may want to filter these out by ignoring individual properties.

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

public class MyComplexObject
{
  public int Id { get; }
  public string Name { get; }
  public bool IsEnabled { get; }
}

public class MyOtherObject
{
  public int Id { get; }
  public string Name { get; }
  public bool IsEnabled { get; }
  public string UniqueProperty { get; }
}