Fixed all remaining CA1416 errors#22868
Conversation
|
@stephen-hawley should we also add this to warnings as errors so we won't introduce any new ones? |
The PR that this branch merges into already turns these into errors so that's not needed here. |
|
/azp run |
|
Azure Pipelines could not run because the pipeline triggers exclude this branch/path. |
| [SupportedOSPlatform("maccatalyst13.1")] | ||
| bool UIStyleMatches (UITraitCollection target) | ||
| { | ||
| return target.UserInterfaceStyle == TraitCollection.UserInterfaceStyle; |
There was a problem hiding this comment.
Are these nullchecks (previousTraitCollection?.UserInterfaceStyle) removed on purpose?
Also I have found that there is method "UITraitCollection.HasDifferentColorAppearanceComparedTo(UITraitCollection previous)" but have not tried.
Maybe this could be cheaper (passing C# referenced object to exported method vs. accessing and comparing two obj-c objects in C# referenced objects and comparing), but I am not sure how it handles "Unspecified" one or null.
(Edit: Second part is bad idea, can compare idiom and more + maybe fooling myself ... UIUserInterfaceStyle contains only "Light", "Dark" and "Unspecified" 🤦♂️, but still this should be in diff. topic, sorry)
This should take care of all the remaining CA1416 errors.
Here's what I found about the analyzer for this -
if (!OperatingSystem.IsZZZZZZVersionAtLeast(major, minor)) return;that implies that the rest of the code in the method is safe, flagging a false failureIn order to work around this, the simplest way is to refactor all the OS version specific code into its own method and flag it with
[SupportedOSPlatform("xxxyy.zz")]. In this case, the above false failures go away.In rare cases, I was unable to do this and instead used a
#pragmato suppress the warning around the code that triggered the false failure. I tried to avoid this at all costs since this is source of bugs waiting to happen.