Skip to content
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

Add platform-specific attributes #38604

Merged
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// 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.InteropServices
{

wli3 marked this conversation as resolved.
Show resolved Hide resolved
/// <summary>
/// Records the minimum platform that is required in order to the marked thing.
wli3 marked this conversation as resolved.
Show resolved Hide resolved
/// <list type="bullet">
/// <item>
/// <description>When applied to an assembly, it means the entire assembly cannot be called
/// into on earlier versions. It records the TargetPlatformMinVersion property.</description>
/// </item>
/// <item>
/// <description> When applied to an API, it means the API cannot be called from an earlier
/// version.</description>
/// </item>
/// </list>
///
/// In either case, the caller can either mark itself with MinimumPlatformAttribute
/// or guard the call with a platform check.
///
/// The attribute can be applied multiple times for different operating systems.
/// That means the API is supported on multiple operating systems.
///
/// A given platform should only be specified once.
/// </summary>
wli3 marked this conversation as resolved.
Show resolved Hide resolved
[AttributeUsage(AttributeTargets.Assembly |
AttributeTargets.Class |
AttributeTargets.Constructor |
AttributeTargets.Event |
AttributeTargets.Method |
AttributeTargets.Module |
AttributeTargets.Property |
AttributeTargets.Struct,
AllowMultiple = true, Inherited = false)]
public sealed class MinimumOSAttribute : PlatformAttribute
wli3 marked this conversation as resolved.
Show resolved Hide resolved
{
public MinimumOSAttribute(string platformName) : base(platformName)
{
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// 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.InteropServices
{
/// <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>
wli3 marked this conversation as resolved.
Show resolved Hide resolved
[AttributeUsage(AttributeTargets.Assembly |
AttributeTargets.Class |
AttributeTargets.Constructor |
AttributeTargets.Event |
AttributeTargets.Method |
AttributeTargets.Module |
AttributeTargets.Property |
AttributeTargets.Struct,
AllowMultiple = true, Inherited = false)]
public sealed class ObsoletedInPlatformAttribute : PlatformAttribute
wli3 marked this conversation as resolved.
Show resolved Hide resolved
{
public ObsoletedInPlatformAttribute(string platformName, string url, string message) : base(platformName)
wli3 marked this conversation as resolved.
Show resolved Hide resolved
{
Url = url;
Message = message;
}

public string Url { get; set; }
public string Message { get; }
}
}
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.InteropServices
{

wli3 marked this conversation as resolved.
Show resolved Hide resolved
/// <summary>
/// Base type for all platform-specific attributes. Primarily used to allow grouping
/// in documentation.
/// </summary>
wli3 marked this conversation as resolved.
Show resolved Hide resolved
public abstract class PlatformAttribute : Attribute
wli3 marked this conversation as resolved.
Show resolved Hide resolved
{
internal PlatformAttribute(string platformName)
wli3 marked this conversation as resolved.
Show resolved Hide resolved
{
PlatformName = platformName;
}
public string PlatformName { get; }
}
}
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.InteropServices
{

wli3 marked this conversation as resolved.
Show resolved Hide resolved
/// <summary>
/// Marks APIs that were removed in a given operating system version.
///
/// Primarily used by OS bindings to indicate APIs that are only available in
/// earlier versions.
/// </summary>
wli3 marked this conversation as resolved.
Show resolved Hide resolved
[AttributeUsage(AttributeTargets.Assembly |
AttributeTargets.Class |
AttributeTargets.Constructor |
AttributeTargets.Event |
AttributeTargets.Method |
AttributeTargets.Module |
AttributeTargets.Property |
AttributeTargets.Struct,
AllowMultiple = true, Inherited = false)]
public sealed class RemovedInPlatformAttribute : PlatformAttribute
wli3 marked this conversation as resolved.
Show resolved Hide resolved
{
public RemovedInPlatformAttribute(string platformName) : base(platformName)
{
}
}
}
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.InteropServices
{
/// <summary>
/// Records the platform that the project targeted.
/// </summary>
[AttributeUsage(AttributeTargets.Assembly,
AllowMultiple = false, Inherited = false)]
public sealed class TargetPlatformAttribute : PlatformAttribute
{
public TargetPlatformAttribute(string platformName) : base(platformName)
{
}
}
}
buyaa-n marked this conversation as resolved.
Show resolved Hide resolved