-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Fix CA1805 for unnecessary initialization of fields #38410
Conversation
Are you going to enable the rule so we don't go backwards (just waiting on that Roslyn fix?) Did the rule have a fixer? |
Eventually. There are a few cases I reverted because they require more follow-up, e.g. #38401, generally where removing the initialization then caused C# to warn that the field was unused, and while I deleted a few, I didn't go through all of them.
Yes, I wrote a fixer for it and used that to do this: |
src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/OutputScopeManager.cs
Outdated
Show resolved
Hide resolved
b9e6b0c
to
a404806
Compare
Wow, that was a lot of "Load Diff" clicking. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good except I don't follow HeaderCollection.cs
I did not review inside Github :)
This has three primary benefits: 1. In some cases, in particular for static fields where other static fields have non-default initialization, the C# compiler can't elide the default initialization, resulting in more IL. 2. It highlights places where the field is otherwise unused and can be deleted, but where the presence of the initialization was silencing the C# compiler's warnings about the unused field. 3. It increases consistency and decreases maintenance / code size / etc.
This has three primary benefits:
cc: @marek-safar, @bartonjs