Skip to content

Compare records by properties when requested#4837

Merged
manfred-brands merged 2 commits intonunit:mainfrom
Dreamescaper:compare_records_by_properties_when_requested
Sep 25, 2024
Merged

Compare records by properties when requested#4837
manfred-brands merged 2 commits intonunit:mainfrom
Dreamescaper:compare_records_by_properties_when_requested

Conversation

@Dreamescaper
Copy link
Member

Fixes #4836 .

If CompareProperties is true, and actual value is record type, I ignore compiler-generated Equals methods, and force it to compare by properties instead.

In order to check that provided type is record, I verify that Equals method has CompilerGeneratedAttribute. Not sure if there's a better way.

I wanted to add a test for class with primary constructor, therefore I increased LangVersion to 12. Let me know if that causes any issues.

Copy link
Member

@manfred-brands manfred-brands left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should assume that the owner of the class knows best. If it explicitly implements Equals(T) it should be called regardless of properties comparer selection.

Also for 90% of record classes which only contain value like properties the generated code is just fine.

@Dreamescaper
Copy link
Member Author

I've updated the PR per your suggestions, thanks!

Copy link
Member

@manfred-brands manfred-brands left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Dreamescaper, looks good now.

@manfred-brands manfred-brands merged commit b10f221 into nunit:main Sep 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PropertiesComparer doesn't work well with records

2 participants