Skip to content

PropertiesComparer doesn't work well with records #4836

@Dreamescaper

Description

@Dreamescaper
record C1
{
    public string Name { get; set; }
    public int[] Collection { get; set; }
}

var v1 = new C1 { Name = "1", Collection = [1, 2, 3] };
var v2 = new C1 { Name = "1", Collection = [1, 2, 3] };

Assert.That(v1, Is.EqualTo(v2).UsingPropertiesComparer());

The assertion above fails, even thouht the same code works fine if I replace "record" with "class".
I assume that the issue is that record is IEquatable, therefore comparer doesn't attempt to compare it by properties.

I would suggest to ignore IEquatable for records in case UsingPropertiesComparer is used, and still compare it property by property.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions