question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CompareLogic considers non equivalent objects as Equal

See original GitHub issue

Hello, 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:closed
  • Created 5 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
GregFinzercommented, Nov 2, 2018

Sorry, I have no idea, you will need to debug the source.

0reactions
medbozcommented, Nov 14, 2018

No problem Good luck

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found