diff options
author | Rolf Bjarne Kvinge <rolf@xamarin.com> | 2022-07-09 02:43:27 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-09 02:43:27 +0300 |
commit | 4dd047a78c793ffa88d0c054c41a1200ed8c9901 (patch) | |
tree | 1590bc38200404a38b11bd2f06504a65cd322b14 /src | |
parent | 983c8f239a98812498d874ed36b7001bd764fdfe (diff) |
Add/implement ObsoletedInOSPlatformAttribute. (#71846)
Diffstat (limited to 'src')
4 files changed, 90 insertions, 0 deletions
diff --git a/src/libraries/System.Private.CoreLib/src/ILLink/ILLink.LinkAttributes.Shared.xml b/src/libraries/System.Private.CoreLib/src/ILLink/ILLink.LinkAttributes.Shared.xml index 5d965dfd023..cb9cabdc3ea 100644 --- a/src/libraries/System.Private.CoreLib/src/ILLink/ILLink.LinkAttributes.Shared.xml +++ b/src/libraries/System.Private.CoreLib/src/ILLink/ILLink.LinkAttributes.Shared.xml @@ -210,6 +210,9 @@ <type fullname="System.Runtime.Versioning.UnsupportedOSPlatformAttribute"> <attribute internal="RemoveAttributeInstances" /> </type> + <type fullname="System.Runtime.Versioning.ObsoletedInOSPlatformAttribute"> + <attribute internal="RemoveAttributeInstances" /> + </type> <type fullname="System.Runtime.Versioning.SupportedOSPlatformGuardAttribute"> <attribute internal="RemoveAttributeInstances" /> </type> diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/Versioning/PlatformAttributes.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/Versioning/PlatformAttributes.cs index 4a0a3753c00..ef235aae222 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/Versioning/PlatformAttributes.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/Versioning/PlatformAttributes.cs @@ -102,6 +102,47 @@ namespace System.Runtime.Versioning public UnsupportedOSPlatformAttribute(string platformName) : base(platformName) { } + public UnsupportedOSPlatformAttribute(string platformName, string? message) : base(platformName) + { + Message = message; + } + public string? Message { get; } + } + + /// <summary> + /// Marks APIs that were obsoleted in a given operating system version. + /// </summary> + /// <remarks> + /// Primarily used by OS bindings to indicate APIs that should not be used anymore. + /// </remarks> + [AttributeUsage(AttributeTargets.Assembly | + AttributeTargets.Class | + AttributeTargets.Constructor | + AttributeTargets.Enum | + AttributeTargets.Event | + AttributeTargets.Field | + AttributeTargets.Interface | + AttributeTargets.Method | + AttributeTargets.Module | + AttributeTargets.Property | + AttributeTargets.Struct, + AllowMultiple = true, Inherited = false)] +#if SYSTEM_PRIVATE_CORELIB + public +#else + internal +#endif + sealed class ObsoletedInOSPlatformAttribute : OSPlatformAttribute + { + public ObsoletedInOSPlatformAttribute(string platformName) : base(platformName) + { + } + public ObsoletedInOSPlatformAttribute(string platformName, string? message) : base(platformName) + { + Message = message; + } + public string? Message { get; } + public string? Url { get; set; } } /// <summary> diff --git a/src/libraries/System.Runtime/ref/System.Runtime.cs b/src/libraries/System.Runtime/ref/System.Runtime.cs index 07abb8a2319..b30665c2d7f 100644 --- a/src/libraries/System.Runtime/ref/System.Runtime.cs +++ b/src/libraries/System.Runtime/ref/System.Runtime.cs @@ -13437,6 +13437,14 @@ namespace System.Runtime.Versioning public static bool operator !=(System.Runtime.Versioning.FrameworkName? left, System.Runtime.Versioning.FrameworkName? right) { throw null; } public override string ToString() { throw null; } } + [System.AttributeUsageAttribute(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Constructor | System.AttributeTargets.Enum | System.AttributeTargets.Event | System.AttributeTargets.Field | System.AttributeTargets.Interface | System.AttributeTargets.Method | System.AttributeTargets.Module | System.AttributeTargets.Property | System.AttributeTargets.Struct, AllowMultiple=true, Inherited=false)] + public sealed partial class ObsoletedInOSPlatformAttribute : System.Runtime.Versioning.OSPlatformAttribute + { + public ObsoletedInOSPlatformAttribute(string platformName) : base(platformName) { } + public ObsoletedInOSPlatformAttribute(string platformName, string? message) : base(platformName) { } + public string? Message { get { throw null; } } + public string? Url { get { throw null; } set {} } + } public abstract partial class OSPlatformAttribute : System.Attribute { private protected OSPlatformAttribute(string platformName) { } @@ -13503,6 +13511,8 @@ namespace System.Runtime.Versioning public sealed partial class UnsupportedOSPlatformAttribute : System.Runtime.Versioning.OSPlatformAttribute { public UnsupportedOSPlatformAttribute(string platformName) : base(platformName) { } + public UnsupportedOSPlatformAttribute(string platformName, string? message) : base(platformName) { } + public string? Message { get { throw null; } } } [System.AttributeUsageAttribute(System.AttributeTargets.Field | System.AttributeTargets.Method | System.AttributeTargets.Property, AllowMultiple=true, Inherited=false)] public sealed partial class UnsupportedOSPlatformGuardAttribute : System.Runtime.Versioning.OSPlatformAttribute diff --git a/src/libraries/System.Runtime/tests/System/Runtime/Versioning/OSPlatformAttributeTests.cs b/src/libraries/System.Runtime/tests/System/Runtime/Versioning/OSPlatformAttributeTests.cs index 332a98e40da..619bdc7c8f1 100644 --- a/src/libraries/System.Runtime/tests/System/Runtime/Versioning/OSPlatformAttributeTests.cs +++ b/src/libraries/System.Runtime/tests/System/Runtime/Versioning/OSPlatformAttributeTests.cs @@ -28,6 +28,19 @@ namespace System.Runtime.Versioning.Tests var tpa = new UnsupportedOSPlatformAttribute(platformName); Assert.Equal(platformName, tpa.PlatformName); + Assert.Null(tpa.Message); + } + + [Theory] + [InlineData("Windows8.0", "Message in a bottle")] + [InlineData("Android4.1", "Message on a pigeon")] + [InlineData("", null)] + public void TestUnsupportedOSPlatformAttributeWithMessage(string platformName, string? message) + { + var tpa = new UnsupportedOSPlatformAttribute(platformName, message); + + Assert.Equal(platformName, tpa.PlatformName); + Assert.Equal(message, tpa.Message); } [Theory] @@ -45,6 +58,29 @@ namespace System.Runtime.Versioning.Tests [InlineData("Windows8.0")] [InlineData("Android4.1")] [InlineData("")] + public void TestObsoletedInOSPlatformAttribute(string platformName) + { + var tpa = new ObsoletedInOSPlatformAttribute(platformName); + + Assert.Equal(platformName, tpa.PlatformName); + } + + [Theory] + [InlineData("Windows8.0", "Message in a bottle")] + [InlineData("Android4.1", "Message on a pigeon")] + [InlineData("", null)] + public void TestObsoletedInOSPlatformAttributeWithMessage(string platformName, string? message) + { + var tpa = new ObsoletedInOSPlatformAttribute(platformName, message); + + Assert.Equal(platformName, tpa.PlatformName); + Assert.Equal(message, tpa.Message); + } + + [Theory] + [InlineData("Windows8.0")] + [InlineData("Android4.1")] + [InlineData("")] public void TestUnsupportedOSPlatformGuardAttribute(string platformName) { var uopga = new UnsupportedOSPlatformGuardAttribute(platformName); |