CsWinRT icon indicating copy to clipboard operation
CsWinRT copied to clipboard

Change #pragma warning solution to suppress SupportedOSPlatform attribute

Open angelazhangmsft opened this issue 4 years ago • 1 comments

Ideally we wouldn't need to suppress a CA1416 warning (like below):

Warning CA1416: This call site is reachable on: 'Windows' 10.0.17763.0 and later. 'DisplayMonitor.IsDolbyVisionSupportedInHdrMode.get' is only supported on: 'Windows' 10.0.19041.0 and later.

By using the #pragma warning:

if (ApiInformation.IsPropertyPresent("Windows.Devices.Display.DisplayMonitor", "IsDolbyVisionSupportedInHdrMode"))
                {
#pragma warning disable CA1416 // Validate platform compatibility
                    Console.WriteLine("IsDolbyVisionSupported: " + displayMonitor.IsDolbyVisionSupportedInHdrMode);
#pragma warning restore CA1416 // Validate platform compatibility
                }

We could update the analyzer to recognize the ApiInformation check so suppressing the warning isn't needed. Also see https://github.com/dotnet/runtime/issues/47593

angelazhangmsft avatar Feb 03 '21 19:02 angelazhangmsft

We either need to build our own analyzer to recognize this, or work with the .NET analyzer to recognize ApiInformation.

AdamBraden avatar Feb 09 '21 18:02 AdamBraden