-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Unify MinimumOSPlatformAttribute and UnsupportedOSPlatformAttribute #39989
Comments
As I commented on in the spec PR, I wonder if we should support [SupportedOSPlatform("ios12.0", "ipados13.0")]
[ObsoletedInOSPlatform("ios13.0")]
[UnsupportedOSPlatform("ios14.0")]
public void OnlyWorksOniOS(); |
Overall, this proposal looks good - it will allow us to model unsupported APIs in Blazor WASM.
It feels like the types |
namespace System.Runtime.Versioning
{
public abstract class OSPlatformAttribute : Attribute
{
private protected OSPlatformAttribute(string platformName);
public string PlatformName { get; }
}
[AttributeUsage(AttributeTargets.Assembly,
AllowMultiple=false, Inherited=false)]
public sealed class TargetPlatformAttribute : OSPlatformAttribute
{
public TargetPlatformAttribute(string platformName);
}
}
namespace System.Runtime.InteropServices
{
// Renamed from MinimumOSPlatformAttribute
[AttributeUsage(AttributeTargets.Assembly |
AttributeTargets.Class |
AttributeTargets.Constructor |
AttributeTargets.Enum |
AttributeTargets.Event |
AttributeTargets.Field |
AttributeTargets.Method |
AttributeTargets.Module |
AttributeTargets.Property |
AttributeTargets.Struct,
AllowMultiple = true, Inherited = false)]
public sealed class SupportedOSPlatformAttribute : OSPlatformAttribute
{
public SupportedOSPlatformAttribute(string platformName);
}
// RemovedInOSPlatformAttribute
[AttributeUsage(AttributeTargets.Assembly |
AttributeTargets.Class |
AttributeTargets.Constructor |
AttributeTargets.Enum |
AttributeTargets.Event |
AttributeTargets.Field |
AttributeTargets.Method |
AttributeTargets.Module |
AttributeTargets.Property |
AttributeTargets.Struct,
AllowMultiple = true, Inherited = false)]
public sealed class UnsupportedOSPlatformAttribute : OSPlatformAttribute
{
public UnsupportedOSPlatformAttribute(string platformName);
}
// Same shape, but different namespace
[AttributeUsage(AttributeTargets.Assembly |
AttributeTargets.Class |
AttributeTargets.Constructor |
AttributeTargets.Event |
AttributeTargets.Method |
AttributeTargets.Module |
AttributeTargets.Property |
AttributeTargets.Struct,
AllowMultiple=true, Inherited=false)]
public sealed class ObsoletedInOSPlatformAttribute : OSPlatformAttribute
{
public ObsoletedInPlatformAttribute(string platformName);
public ObsoletedInPlatformAttribute(string platformName, string message);
public string Message { get; }
public string Url { get; set; }
}
} |
The original proposal for marking-platform-specific APIs only considered cases where an API was platform-specific, such as the Windows registry. When trying to design a solution for marking APIs as unsupported by Blazor, it became obvious that we need a way to exclude some platforms without treating the API as platform-specific. Hence, a proposal for platform-exclusion was born dotnet/designs#143.
During the design, it emerged that it would be desirable to align these two proposals.
API proposal
MinimumOSPlatformAttribute
toSupportedOSPlatformAttribute
RemovedInOSPlatformAttribute
toUnsupportedOSPlatformAttribute
The semantics of these new attributes are as follows:
[SupportedOSPlatform]
or[UnsupportedOSPlatform]
attributes are present, we group all attributes by OS platform identifier:[SupportedOSPlatform]
attribute, the API is considered to only be supported by the listed platforms and unsupported by all other platforms.[UnsupportedOSPlatform]
attribute, then the API is considered to only be unsupported by the listed platforms and supported by all other platforms.[SupportedOSPlatform]
while for others it is[UnsupportedOSPlatform]
, the analyzer will produce a warning on the API definition because the API is attributed inconsistently.0.0
. This simplifies guard clauses, see examples below for more details.[ObsoletedInOSPlatform]
continuous to require a version number.[ObsoletedInOSPlatform]
by itself doesn't imply support. However, it doesn't make sense to apply[ObsoletedInOSPlatform]
unless that platform is supported.API Usage
Unsuported platform
In .NET 5:
In .NET 6 we change the code to support the API, but only on Windows 10:
Platform-specific API
Related
The text was updated successfully, but these errors were encountered: