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

Analyzer to prefer equality operator over object.equals calls for enums #41567

Open
Mrnikbobjeff opened this issue Aug 30, 2020 · 5 comments
Open
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.Runtime code-analyzer Marks an issue that suggests a Roslyn analyzer
Milestone

Comments

@Mrnikbobjeff
Copy link

Mrnikbobjeff commented Aug 30, 2020

Enums shoud always be compared by using == when testing for equality. In Xamarin.Essentials I saw the use of .Equals calls to compare enums for equality, which does the same but incurs a box for enums. A roslyn analyzer can easily detect calls to object.Equals calls where the argument is an enum. I already have a working implementation of this analyzer if this is a desirable feature.

@Dotnet-GitSync-Bot
Copy link
Collaborator

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added the untriaged New issue has not been triaged by the area owner label Aug 30, 2020
@ghost
Copy link

ghost commented Aug 30, 2020

Tagging subscribers to this area: @CoffeeFlux
See info in area-owners.md if you want to be subscribed.

@CoffeeFlux
Copy link
Contributor

What is the exact suggestion here—that Roslyn add an analyzer for this or that Xamarin.Essentials switch what they're using? In either case, I think this issue is better filed in the respective repo.

@Mrnikbobjeff
Copy link
Author

Mrnikbobjeff commented Aug 30, 2020

Xamarin.Essentials was the first place where I found this pattern. As there are other analyzer suggestions listed here such as #33773 and the board I thought this might be the place for it.

@CoffeeFlux CoffeeFlux added area-System.Runtime code-analyzer Marks an issue that suggests a Roslyn analyzer and removed area-VM-meta-mono labels Aug 30, 2020
@jeffhandley
Copy link
Member

Thanks for this feature idea and the offer to contribute an analyzer, @Mrnikbobjeff.

I'm going to move this into our Future milestone as we wouldn't be able to include this in 5.0 at this point. @terrajobst / @bartonjs, would we want to do a full API review for this one, or do you think this is straightforward enough to give the go-ahead for a PR into dotnet/roslyn-analyzers (for after 5.0)?

@jeffhandley jeffhandley added this to the Future milestone Sep 3, 2020
@jeffhandley jeffhandley removed the untriaged New issue has not been triaged by the area owner label Sep 3, 2020
@buyaa-n buyaa-n added the api-suggestion Early API idea and discussion, it is NOT ready for implementation label Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.Runtime code-analyzer Marks an issue that suggests a Roslyn analyzer
Projects
None yet
Development

No branches or pull requests

6 participants