You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[generator] Add [SupportedOSPlatform] in assemblies using ApiSince (#773)
Context: dotnet/android#5338
.NET 5 provides a new
[`System.Runtime.Versioning.SupportedOSPlatformAttribute`][0] custom
attribute which is used to specify on which platforms and platform
versions an API is available. This is used to build analyzers to give
users warnings if they are trying to use an API when it will not be
available on their target platform.
`SupportedOSPlatformAttribute` is fundamentally the same as our
existing `RegisterAttribute.ApiSince` property, except tooling has
actually been built to consume the information.
As such, we need `generator` support to put this information into
`Mono.Android.dll`:
partial class Activity {
// Metadata.xml XPath method reference: path="/api/package[@name='android.app']/class[@name='Activity']/method[@name='dismissKeyboardShortcutsHelper' and count(parameter)=0]"
[global::System.Runtime.Versioning.SupportedOSPlatformAttribute ("android24.0")]
[Register ("dismissKeyboardShortcutsHelper", "()V", "", ApiSince = 24)]
public unsafe void DismissKeyboardShortcutsHelper () { … }
}
Some interesting notes:
- `SupportedOSPlatformAttribute` is only available in .NET 5+, so
we include a local version for earlier frameworks so we can
compile without needing to `#ifdef` every attribute use.
- The local version is marked as `[Conditional ("NEVER")]` so the
attributes will not actually get compiled into the resulting
pre-NET5.0 assembly.
- The attribute cannot be placed on interfaces or fields, so we
aren't able to annotate them.
- Our minimum supported API for .NET 6 is 21, so we only write
attributes for API added in versions newer than 21, as API added
earlier are always available.
[0]: https://docs.microsoft.com/en-us/dotnet/api/system.runtime.versioning.supportedosplatformattribute?view=net-5.0
0 commit comments