CA1416 Support custom guard members annotated with guard attributes#5087
Merged
Conversation
Codecov Report
@@ Coverage Diff @@
## release/6.0.1xx #5087 +/- ##
===================================================
+ Coverage 95.55% 95.57% +0.01%
===================================================
Files 1203 1203
Lines 274337 274837 +500
Branches 16632 16653 +21
===================================================
+ Hits 262137 262662 +525
+ Misses 9988 9970 -18
+ Partials 2212 2205 -7 |
jeffhandley
reviewed
May 7, 2021
Member
jeffhandley
left a comment
There was a problem hiding this comment.
I'm still reviewing, but I wanted to go ahead and post the comments I have so far.
mavasani
reviewed
May 11, 2021
mavasani
reviewed
May 11, 2021
mavasani
reviewed
May 11, 2021
mavasani
reviewed
May 11, 2021
mavasani
approved these changes
May 11, 2021
mavasani
left a comment
There was a problem hiding this comment.
Please do retarget to 6.0.1xx branch
jeffhandley
approved these changes
May 12, 2021
This was referenced May 12, 2021
Merged
Merged
This was referenced Aug 31, 2021
This was referenced Sep 10, 2021
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4428 Related to dotnet/runtime#51541 and dotnet/runtime#44922 (comment)
The CA1416 Platform Compatibility analyzer already recognizes platform guards using the methods on OperatingSystem/RuntimeInformation, such as OperatingSystem.IsWindows and OperatingSystem.IsWindowsVersionAtLeast. However, the analyzer does not recognize other guard options like when a field, property, or helper methods cached the platform check result and used as platform guards.
Expanding this support involved adding new attributes
SupportedOSPlatformGuardandUnsupportedOSPlatformGuardand annotated the custom guards with those attributes with the corresponding platform and/or version. Now this annotation needs to be recognized and respected in the Platform Compatibility analyzer flow analysisUsage Examples
Thread.IsThreadStartSupportedindicates whether or not the current platform supports calls toThread.Start(), which is not supported onbrowser. So in this[UnsupportedOSPlatformGuard]attributes can be used for this field and the analyzer will recognize it as a platform guard.Example with helper method:
For guarding multiple platforms need to apply the attribute for each platform