Hide ReferenceEquals and Equals for custom types in IntelliSence #59333
Replies: 5 comments 8 replies
-
@sharwell any concerns doing this? |
Beta Was this translation helpful? Give feedback.
-
The part about static-class can't be implemented by EditorBrowsableAttribute. It should be handled directly in IntelliSense logic.
Did you mean about You've not explicitly rejected the following cases:Static classesThere no one reason for existing The static classes are implemented System.Object. But it is the details of implementation from user side. It's good to always warning the user that the current code is unclear/not modern and safe. Struct EqualsAre you agree this is incorrect method always? For all structs? int.Equals(3, 5); We understand this case only because we remembered what wrong with it. This will allow us to forget one special case in the infrastructure, it reduces the language barrier. This bug quite easily introduced by changing class to struct. The new analyzer will display some warning. The endIt was strange not to find anything on the Internet about this. It was my duty to report this. If the new small rules will be more modern, why not gently point users to this. FYI @stephentoub |
Beta Was this translation helpful? Give feedback.
-
#59420 (reply in thread)
Currently, the static classes are common classes with private constructor. Is it not a language changes? Since this changes the internals of C#, I suggest simply hiding Similar situation with structs. |
Beta Was this translation helpful? Give feedback.
-
Wow, The Czech rider hides ReferenceEquals and Equals from all types, except object and string (only string.ReferenceEquals is hidden). Amazing attention to details. I don't know if R# does it or not. |
Beta Was this translation helpful? Give feedback.
-
For what it's worth, I'm in agreement that it's unnecessary clutter. I'm done writing a simple 2D Game framework for Game Design college students, using a lot of simple static classes to manage key variables and function calls. However, If this isn't something to edit on the implementation side, can't there just be one more checkbox in the sea of checkboxes in Options to hide it (or any other editor change), as Yegor mentioned Rider does something similar? |
Beta Was this translation helpful? Give feedback.
-
Introduction
It's annoying to see ReferenceEquals and Equals anywhere.
Static classes
Both methods are meaningless:
Assert
, SerilogLog
and small user's helper classes suffer from this at code completion.Struct
The static Equals is wrong for any struct.
This bug easily appears when changing a class to a struct in a user type.
ReferenceEquals
ReferenceEquals is used via object or via direct call. I've never seen the code like:
Also this is a low-level method, but you see it at every code completion for a type.
Proposal
Hide static Equals for structs and static classes.
Hide ReferenceEquals for all types, except object.
This should be done by hiding them from IntelliSense. The new analyzer will complain about the use of these hidden methods.
Questions
Should the direct Equals call be hidden? It will help to better detect the "changing a class to a struct" bug.
Beta Was this translation helpful? Give feedback.
All reactions