-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
IDE0052 fires on write-only properties #30894
Comments
This is by design. For majority of realistic code examples, a write-only property is very likely dead code and this violation will help them clean up their code. For questionable examples such as the one mentioned here, the write-only property should be converted to a method OR the violation should be suppressed if it is legacy code. |
Can you show me exactly of what you claim as realistic write-only properties that are dead code? Every single write-only property in this code is noise. |
I don't think there is any modern code base that uses private write-only properties, except if they sneaked in by accident when code was getting refactored. Can you show me any other open source repo, except the legacy VB projects in project-system that uses one? Regardless, given these are extremely rare, and even if they exist are a questionable API design choice, I would be fine with us detecting and bailing out on these. I am re-opening this issue and will confirm it in the next design meeting. |
@mavasani possibly worth having a sub-option for this? so people can say "actually, in my code we do use this pattern", but others can say "yeah... i would consider that strange, let me get rid of it" Also, we do have a convert-property-to-method refactoring. But i'm not actually sure it works on write-only properties. :D |
@CyrusNajmabadi Given these are so rare, for now I am going to submit a PR for this analyzer to bail out on write-only properties to remove the noise that @davkean is seeing. We should likely have an option OR report a different diagnostic for write-only properties, suggesting replacing them with methods. I will file a separate issue and bring that up for design review next week. |
Filed #30983 |
While write-only properties are questionable, just because they don't have a getter doesn't mean they can be removed.
Later:
Expected: No warning
Actual:
The text was updated successfully, but these errors were encountered: