Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detecting record fields than don’t have value semantics #1211

Open
lookbusy1344 opened this issue Sep 26, 2023 · 1 comment
Open

Detecting record fields than don’t have value semantics #1211

lookbusy1344 opened this issue Sep 26, 2023 · 1 comment

Comments

@lookbusy1344
Copy link

lookbusy1344 commented Sep 26, 2023

Is it possible to check records for field types that lack a customised Equals override, or that use reference equality? These fields can cause subtle bugs, and I’m not aware of any way to detect this at present. Eg

public record Info(DirectoryInfo Folder, string Name);

var a = new Info(new DirectoryInfo("."), "test");
var b = new Info(new DirectoryInfo("."), "test");

var same = a == b; // false!

DirectoryInfo has reference semantics, so isn’t suitable for use in records without a custom Equals check.

Is it possible to create a warning for this kind of issue?

@lookbusy1344
Copy link
Author

I wrote one myself that seems to work ok: https://github.com/lookbusy1344/RecordValueAnalyser

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

No branches or pull requests

1 participant