-
Notifications
You must be signed in to change notification settings - Fork 468
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
CA1416 Support custom guard members annotated with guard attributes #5087
Conversation
...zers/Core/Microsoft.NetCore.Analyzers/InteropServices/PlatformCompatibilityAnalyzer.Value.cs
Show resolved
Hide resolved
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 |
...ft.NetCore.Analyzers/InteropServices/PlatformCompatibilityAnalyzerTests.GuardedCallsTests.cs
Show resolved
Hide resolved
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.
I'm still reviewing, but I wanted to go ahead and post the comments I have so far.
...icrosoft.NetCore.Analyzers/InteropServices/PlatformCompatibilityAnalyzer.OperationVisitor.cs
Outdated
Show resolved
Hide resolved
...icrosoft.NetCore.Analyzers/InteropServices/PlatformCompatibilityAnalyzer.OperationVisitor.cs
Outdated
Show resolved
Hide resolved
...zers/Core/Microsoft.NetCore.Analyzers/InteropServices/PlatformCompatibilityAnalyzer.Value.cs
Outdated
Show resolved
Hide resolved
...tAnalyzers/Core/Microsoft.NetCore.Analyzers/InteropServices/PlatformCompatibilityAnalyzer.cs
Outdated
Show resolved
Hide resolved
...ft.NetCore.Analyzers/InteropServices/PlatformCompatibilityAnalyzerTests.GuardedCallsTests.cs
Outdated
Show resolved
Hide resolved
...ft.NetCore.Analyzers/InteropServices/PlatformCompatibilityAnalyzerTests.GuardedCallsTests.cs
Show resolved
Hide resolved
...ft.NetCore.Analyzers/InteropServices/PlatformCompatibilityAnalyzerTests.GuardedCallsTests.cs
Show resolved
Hide resolved
...icrosoft.NetCore.Analyzers/InteropServices/PlatformCompatibilityAnalyzer.OperationVisitor.cs
Outdated
Show resolved
Hide resolved
...icrosoft.NetCore.Analyzers/InteropServices/PlatformCompatibilityAnalyzer.OperationVisitor.cs
Outdated
Show resolved
Hide resolved
...icrosoft.NetCore.Analyzers/InteropServices/PlatformCompatibilityAnalyzer.OperationVisitor.cs
Outdated
Show resolved
Hide resolved
...icrosoft.NetCore.Analyzers/InteropServices/PlatformCompatibilityAnalyzer.OperationVisitor.cs
Outdated
Show resolved
Hide resolved
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.
Please do retarget to 6.0.1xx branch
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
SupportedOSPlatformGuard
andUnsupportedOSPlatformGuard
and 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.IsThreadStartSupported
indicates 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