-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Add platform-specific attributes #38604
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jeffhandley
merged 9 commits into
dotnet:master
from
wli3:dev/wul/add-in-platform-specific-attribute
Jul 1, 2020
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c40d0e8
Add platform-specific attributes
7475169
Convert to xml doc
a426eb2
Update src/libraries/System.Private.CoreLib/src/System/Runtime/Intero…
7df9b8d
Update src/libraries/System.Private.CoreLib/src/System/Runtime/Intero…
e930a2b
Address code review
e67c82c
Merge branch 'master' of https://github.com/dotnet/runtime into dev/w…
buyaa-n 94ac598
Add to ref assembly, test and fix build errors
buyaa-n c16ab65
Fix spacing, revert unwanted changes
buyaa-n d79d833
Namespace was wrong, updated
buyaa-n File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...raries/System.Private.CoreLib/src/System/Runtime/Versioning/MinimumOSPlatformAttribute.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| namespace System.Runtime.Versioning | ||
| { | ||
| /// <summary> | ||
| /// Records the operating system (and minimum version) that supports an API. Multiple attributes can be | ||
| /// applied to indicate support on multiple operating systems. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// Callers can apply a <see cref="System.Runtime.Versioning.MinimumOSPlatformAttribute" /> | ||
| /// or use guards to prevent calls to APIs on unsupported operating systems. | ||
| /// | ||
| /// A given platform should only be specified once. | ||
| /// </remarks> | ||
| [AttributeUsage(AttributeTargets.Assembly | | ||
| AttributeTargets.Class | | ||
| AttributeTargets.Constructor | | ||
| AttributeTargets.Event | | ||
| AttributeTargets.Method | | ||
| AttributeTargets.Module | | ||
| AttributeTargets.Property | | ||
| AttributeTargets.Struct, | ||
| AllowMultiple = true, Inherited = false)] | ||
| public sealed class MinimumOSPlatformAttribute : OSPlatformAttribute | ||
| { | ||
| public MinimumOSPlatformAttribute(string platformName) : base(platformName) | ||
| { | ||
| } | ||
| } | ||
| } |
20 changes: 20 additions & 0 deletions
20
src/libraries/System.Private.CoreLib/src/System/Runtime/Versioning/OSPlatformAttribute.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| namespace System.Runtime.Versioning | ||
| { | ||
| /// <summary> | ||
| /// Base type for all platform-specific API attributes. | ||
| /// </summary> | ||
| #pragma warning disable CS3015 // Type has no accessible constructors which use only CLS-compliant types | ||
| public abstract class OSPlatformAttribute : Attribute | ||
| #pragma warning restore CS3015 | ||
| { | ||
| private protected OSPlatformAttribute(string platformName) | ||
| { | ||
| PlatformName = platformName; | ||
| } | ||
| public string PlatformName { get; } | ||
| } | ||
| } |
36 changes: 36 additions & 0 deletions
36
...es/System.Private.CoreLib/src/System/Runtime/Versioning/ObsoletedInOSPlatformAttribute.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| namespace System.Runtime.Versioning | ||
| { | ||
| /// <summary> | ||
| /// Marks APIs that were obsoleted in a given operating system version. | ||
| /// | ||
| /// Primarily used by OS bindings to indicate APIs that should only be used in | ||
| /// earlier versions. | ||
| /// </summary> | ||
| [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 ObsoletedInOSPlatformAttribute(string platformName) : base(platformName) | ||
| { | ||
| } | ||
|
|
||
| public ObsoletedInOSPlatformAttribute(string platformName, string message) : base(platformName) | ||
| { | ||
| Message = message; | ||
| } | ||
|
|
||
| public string? Message { get; } | ||
| public string? Url { get; set; } | ||
| } | ||
| } |
29 changes: 29 additions & 0 deletions
29
...ries/System.Private.CoreLib/src/System/Runtime/Versioning/RemovedInOSPlatformAttribute.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| namespace System.Runtime.Versioning | ||
| { | ||
| /// <summary> | ||
| /// Marks APIs that were removed in a given operating system version. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// Primarily used by OS bindings to indicate APIs that are only available in | ||
| /// earlier versions. | ||
| /// </remarks> | ||
| [AttributeUsage(AttributeTargets.Assembly | | ||
| AttributeTargets.Class | | ||
| AttributeTargets.Constructor | | ||
| AttributeTargets.Event | | ||
| AttributeTargets.Method | | ||
| AttributeTargets.Module | | ||
| AttributeTargets.Property | | ||
| AttributeTargets.Struct, | ||
| AllowMultiple = true, Inherited = false)] | ||
| public sealed class RemovedInOSPlatformAttribute : OSPlatformAttribute | ||
| { | ||
| public RemovedInOSPlatformAttribute(string platformName) : base(platformName) | ||
| { | ||
| } | ||
| } | ||
| } |
18 changes: 18 additions & 0 deletions
18
...libraries/System.Private.CoreLib/src/System/Runtime/Versioning/TargetPlatformAttribute.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| namespace System.Runtime.Versioning | ||
| { | ||
| /// <summary> | ||
| /// Records the platform that the project targeted. | ||
| /// </summary> | ||
| [AttributeUsage(AttributeTargets.Assembly, | ||
| AllowMultiple = false, Inherited = false)] | ||
| public sealed class TargetPlatformAttribute : OSPlatformAttribute | ||
| { | ||
| public TargetPlatformAttribute(string platformName) : base(platformName) | ||
| { | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/libraries/System.Runtime/tests/System/Runtime/Versioning/OSPlatformAttributeTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| using System.Diagnostics.CodeAnalysis; | ||
| using Xunit; | ||
|
|
||
| namespace System.Runtime.Versioning.Tests | ||
| { | ||
| public class OSPlatformAttributeTests | ||
| { | ||
| [Theory] | ||
| [InlineData("Windows10.0")] | ||
| [InlineData("iOS")] | ||
| [InlineData("")] | ||
| public void TestTargetPlatformAttribute(string platformName) | ||
| { | ||
| var tpa = new TargetPlatformAttribute(platformName); | ||
|
|
||
| Assert.Equal(platformName, tpa.PlatformName); | ||
| } | ||
|
|
||
| [Theory] | ||
| [InlineData("Windows8.0", "Obsolete", "http://test.com/obsoletedInOSPlatform")] | ||
| [InlineData("Linux", "Message", null)] | ||
| [InlineData("iOS13", null, null)] | ||
| [InlineData("", null, "http://test.com/obsoletedInOSPlatform")] | ||
| public void TestObsoletedInOSPlatformAttribute(string platformName, string message, string url) | ||
| { | ||
| var opa = message == null ? new ObsoletedInOSPlatformAttribute(platformName) { Url = url} : new ObsoletedInOSPlatformAttribute(platformName, message) { Url = url }; | ||
|
|
||
| Assert.Equal(platformName, opa.PlatformName); | ||
| Assert.Equal(message, opa.Message); | ||
| Assert.Equal(url, opa.Url); | ||
| } | ||
|
|
||
| [Theory] | ||
| [InlineData("Windows8.0")] | ||
| [InlineData("Android4.1")] | ||
| [InlineData("")] | ||
| public void TestRemovedInOSPlatformAttribute(string platformName) | ||
| { | ||
| var tpa = new RemovedInOSPlatformAttribute(platformName); | ||
|
|
||
| Assert.Equal(platformName, tpa.PlatformName); | ||
| } | ||
|
|
||
| [Theory] | ||
| [InlineData("Windows10.0")] | ||
| [InlineData("OSX")] | ||
| [InlineData("")] | ||
| public void TestMinimumOSPlatformAttribute(string platformName) | ||
| { | ||
| var tpa = new MinimumOSPlatformAttribute(platformName); | ||
|
|
||
| Assert.Equal(platformName, tpa.PlatformName); | ||
| } | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.