CompareLogic considers non equivalent objects as Equal
See original GitHub issueHello,
I don’t know if I’m using CompareLogic in the wrong way, but I’m getting a weird behaviour as reproduced in TestCompare()
bellow:
using System;
using KellermanSoftware.CompareNetObjects;
using NUnit.Framework;
namespace TestCompareNetObjects
{
public class Sample
{
public Sample(string value)
{
Value = value;
}
public String Value { get; }
private bool Equals(Sample other)
{
return string.Equals(Value, other.Value);
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false;
return Equals((Sample) obj);
}
public override int GetHashCode()
{
return Value != null ? Value.GetHashCode() : 0;
}
}
[TestFixture]
public class TestCompareNetObjects
{
[Test]
public void TestCompare()
{
var compareLogic = new CompareLogic
{
Config =
{
ComparePrivateFields = true,
CompareProperties = true,
CompareReadOnly = true,
CompareFields = true,
}
};
var sample1 = new Sample("A");
var sample2 = new Sample("ABC");
var comparisonResult = compareLogic.Compare(sample1, sample2);
Assert.IsFalse(comparisonResult.AreEqual);//this fails (comparisonResult.AreEqual is True)
}
}
}
Issue Analytics
- State:
- Created 5 years ago
- Comments:10 (5 by maintainers)
Top Results From Across the Web
Using Objects Comparer To Compare Complex Objects In C#
If true and the member does not exist, Objects Comparer will consider that this member is equal to the default value of the...
Read more >c# - KellermanSoftware CompareNetObjects, comparing ...
The above two objects compare as not equal, even though the only difference between the two objects is one uses an array, and...
Read more >Using ObjectsComparer to compare objects in .Net
If true and member does not exist, Objects Comparer will consider that this member is equal to default value of opposite member type....
Read more >Resolving aborts after "analyze abort -compare"
I am trying to compare RTL to netlist of a design and after mapping compare and analyze abort -compare I am still left...
Read more >How to define value equality for a class or struct - C# ...
Equals (y) return the same value as long as the objects referenced by x and y aren't modified. Any non-null value isn't equal...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Sorry, I have no idea, you will need to debug the source.
No problem Good luck