|
| 1 | +// Licensed to the .NET Foundation under one or more agreements. |
| 2 | +// The .NET Foundation licenses this file to you under the MIT license. |
| 3 | + |
| 4 | +#pragma warning disable S1694 |
| 5 | +#pragma warning disable S3996 |
| 6 | +#pragma warning disable SA1128 |
| 7 | +#pragma warning disable SA1402 |
| 8 | +#pragma warning disable SA1513 |
| 9 | +#pragma warning disable SA1649 |
| 10 | + |
| 11 | +namespace System.Runtime.Versioning |
| 12 | +{ |
| 13 | + /// <summary> |
| 14 | + /// Base type for all platform-specific API attributes. |
| 15 | + /// </summary> |
| 16 | +#pragma warning disable CS3015 // Type has no accessible constructors which use only CLS-compliant types |
| 17 | + internal abstract class OSPlatformAttribute : Attribute |
| 18 | +#pragma warning restore CS3015 |
| 19 | + { |
| 20 | + private protected OSPlatformAttribute(string platformName) |
| 21 | + { |
| 22 | + PlatformName = platformName; |
| 23 | + } |
| 24 | + public string PlatformName { get; } |
| 25 | + } |
| 26 | + |
| 27 | + /// <summary> |
| 28 | + /// Records the platform that the project targeted. |
| 29 | + /// </summary> |
| 30 | + [AttributeUsage(AttributeTargets.Assembly, |
| 31 | + AllowMultiple = false, Inherited = false)] |
| 32 | + internal sealed class TargetPlatformAttribute : OSPlatformAttribute |
| 33 | + { |
| 34 | + public TargetPlatformAttribute(string platformName) : base(platformName) |
| 35 | + { |
| 36 | + } |
| 37 | + } |
| 38 | + |
| 39 | + /// <summary> |
| 40 | + /// Records the operating system (and minimum version) that supports an API. Multiple attributes can be |
| 41 | + /// applied to indicate support on multiple operating systems. |
| 42 | + /// </summary> |
| 43 | + /// <remarks> |
| 44 | + /// Callers can apply a <see cref="SupportedOSPlatformAttribute " /> |
| 45 | + /// or use guards to prevent calls to APIs on unsupported operating systems. |
| 46 | + /// |
| 47 | + /// A given platform should only be specified once. |
| 48 | + /// </remarks> |
| 49 | + [AttributeUsage(AttributeTargets.Assembly | |
| 50 | + AttributeTargets.Class | |
| 51 | + AttributeTargets.Constructor | |
| 52 | + AttributeTargets.Enum | |
| 53 | + AttributeTargets.Event | |
| 54 | + AttributeTargets.Field | |
| 55 | + AttributeTargets.Interface | |
| 56 | + AttributeTargets.Method | |
| 57 | + AttributeTargets.Module | |
| 58 | + AttributeTargets.Property | |
| 59 | + AttributeTargets.Struct, |
| 60 | + AllowMultiple = true, Inherited = false)] |
| 61 | + internal sealed class SupportedOSPlatformAttribute : OSPlatformAttribute |
| 62 | + { |
| 63 | + public SupportedOSPlatformAttribute(string platformName) : base(platformName) |
| 64 | + { |
| 65 | + } |
| 66 | + } |
| 67 | + |
| 68 | + /// <summary> |
| 69 | + /// Marks APIs that were removed in a given operating system version. |
| 70 | + /// </summary> |
| 71 | + /// <remarks> |
| 72 | + /// Primarily used by OS bindings to indicate APIs that are only available in |
| 73 | + /// earlier versions. |
| 74 | + /// </remarks> |
| 75 | + [AttributeUsage(AttributeTargets.Assembly | |
| 76 | + AttributeTargets.Class | |
| 77 | + AttributeTargets.Constructor | |
| 78 | + AttributeTargets.Enum | |
| 79 | + AttributeTargets.Event | |
| 80 | + AttributeTargets.Field | |
| 81 | + AttributeTargets.Interface | |
| 82 | + AttributeTargets.Method | |
| 83 | + AttributeTargets.Module | |
| 84 | + AttributeTargets.Property | |
| 85 | + AttributeTargets.Struct, |
| 86 | + AllowMultiple = true, Inherited = false)] |
| 87 | + internal sealed class UnsupportedOSPlatformAttribute : OSPlatformAttribute |
| 88 | + { |
| 89 | + public UnsupportedOSPlatformAttribute(string platformName) : base(platformName) |
| 90 | + { |
| 91 | + } |
| 92 | + public UnsupportedOSPlatformAttribute(string platformName, string? message) : base(platformName) |
| 93 | + { |
| 94 | + Message = message; |
| 95 | + } |
| 96 | + public string? Message { get; } |
| 97 | + } |
| 98 | + |
| 99 | + /// <summary> |
| 100 | + /// Marks APIs that were obsoleted in a given operating system version. |
| 101 | + /// </summary> |
| 102 | + /// <remarks> |
| 103 | + /// Primarily used by OS bindings to indicate APIs that should not be used anymore. |
| 104 | + /// </remarks> |
| 105 | + [AttributeUsage(AttributeTargets.Assembly | |
| 106 | + AttributeTargets.Class | |
| 107 | + AttributeTargets.Constructor | |
| 108 | + AttributeTargets.Enum | |
| 109 | + AttributeTargets.Event | |
| 110 | + AttributeTargets.Field | |
| 111 | + AttributeTargets.Interface | |
| 112 | + AttributeTargets.Method | |
| 113 | + AttributeTargets.Module | |
| 114 | + AttributeTargets.Property | |
| 115 | + AttributeTargets.Struct, |
| 116 | + AllowMultiple = true, Inherited = false)] |
| 117 | + internal sealed class ObsoletedOSPlatformAttribute : OSPlatformAttribute |
| 118 | + { |
| 119 | + public ObsoletedOSPlatformAttribute(string platformName) : base(platformName) |
| 120 | + { |
| 121 | + } |
| 122 | + public ObsoletedOSPlatformAttribute(string platformName, string? message) : base(platformName) |
| 123 | + { |
| 124 | + Message = message; |
| 125 | + } |
| 126 | + public string? Message { get; } |
| 127 | + public string? Url { get; set; } |
| 128 | + } |
| 129 | + |
| 130 | + /// <summary> |
| 131 | + /// Annotates a custom guard field, property or method with a supported platform name and optional version. |
| 132 | + /// Multiple attributes can be applied to indicate guard for multiple supported platforms. |
| 133 | + /// </summary> |
| 134 | + /// <remarks> |
| 135 | + /// Callers can apply a <see cref="SupportedOSPlatformGuardAttribute " /> to a field, property or method |
| 136 | + /// and use that field, property or method in a conditional or assert statements in order to safely call platform specific APIs. |
| 137 | + /// |
| 138 | + /// The type of the field or property should be boolean, the method return type should be boolean in order to be used as platform guard. |
| 139 | + /// </remarks> |
| 140 | + [AttributeUsage(AttributeTargets.Field | |
| 141 | + AttributeTargets.Method | |
| 142 | + AttributeTargets.Property, |
| 143 | + AllowMultiple = true, Inherited = false)] |
| 144 | + internal sealed class SupportedOSPlatformGuardAttribute : OSPlatformAttribute |
| 145 | + { |
| 146 | + public SupportedOSPlatformGuardAttribute(string platformName) : base(platformName) |
| 147 | + { |
| 148 | + } |
| 149 | + } |
| 150 | + |
| 151 | + /// <summary> |
| 152 | + /// Annotates the custom guard field, property or method with an unsupported platform name and optional version. |
| 153 | + /// Multiple attributes can be applied to indicate guard for multiple unsupported platforms. |
| 154 | + /// </summary> |
| 155 | + /// <remarks> |
| 156 | + /// Callers can apply a <see cref="UnsupportedOSPlatformGuardAttribute " /> to a field, property or method |
| 157 | + /// and use that field, property or method in a conditional or assert statements as a guard to safely call APIs unsupported on those platforms. |
| 158 | + /// |
| 159 | + /// The type of the field or property should be boolean, the method return type should be boolean in order to be used as platform guard. |
| 160 | + /// </remarks> |
| 161 | + [AttributeUsage(AttributeTargets.Field | |
| 162 | + AttributeTargets.Method | |
| 163 | + AttributeTargets.Property, |
| 164 | + AllowMultiple = true, Inherited = false)] |
| 165 | + internal sealed class UnsupportedOSPlatformGuardAttribute : OSPlatformAttribute |
| 166 | + { |
| 167 | + public UnsupportedOSPlatformGuardAttribute(string platformName) : base(platformName) |
| 168 | + { |
| 169 | + } |
| 170 | + } |
| 171 | +} |
0 commit comments