|
| 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +// Licensed under the MIT license. |
| 3 | + |
| 4 | +// Polyfill for ExperimentalAttribute which is only available in .NET 8+. |
| 5 | +// Since the compiler queries for this attribute by name, having it source-included |
| 6 | +// is sufficient for the compiler to recognize it. |
| 7 | +namespace System.Diagnostics.CodeAnalysis |
| 8 | +{ |
| 9 | +#if !NET8_0_OR_GREATER |
| 10 | + /// <summary> |
| 11 | + /// Indicates that an API is experimental and it may change in the future. |
| 12 | + /// </summary> |
| 13 | + /// <remarks> |
| 14 | + /// This attribute allows call sites to be flagged with a diagnostic that indicates that an experimental |
| 15 | + /// feature is used. Authors can use this attribute to ship preview features in their assemblies. |
| 16 | + /// </remarks> |
| 17 | + [AttributeUsage( |
| 18 | + AttributeTargets.Assembly | AttributeTargets.Module | AttributeTargets.Class | AttributeTargets.Struct | |
| 19 | + AttributeTargets.Enum | AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | |
| 20 | + AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Interface | AttributeTargets.Delegate, |
| 21 | + Inherited = false)] |
| 22 | + internal sealed class ExperimentalAttribute : Attribute |
| 23 | + { |
| 24 | + /// <summary> |
| 25 | + /// Initializes a new instance of the <see cref="ExperimentalAttribute"/> class, |
| 26 | + /// specifying the ID that the compiler will use when reporting a use of the API. |
| 27 | + /// </summary> |
| 28 | + /// <param name="diagnosticId">The ID that the compiler will use when reporting a use of the API.</param> |
| 29 | + public ExperimentalAttribute(string diagnosticId) |
| 30 | + { |
| 31 | + DiagnosticId = diagnosticId; |
| 32 | + } |
| 33 | + |
| 34 | + /// <summary> |
| 35 | + /// Gets the ID that the compiler will use when reporting a use of the API. |
| 36 | + /// </summary> |
| 37 | + public string DiagnosticId { get; } |
| 38 | + |
| 39 | + /// <summary> |
| 40 | + /// Gets or sets the URL for corresponding documentation. |
| 41 | + /// The API accepts a format string instead of an actual URL, creating a generic URL that includes the diagnostic ID. |
| 42 | + /// </summary> |
| 43 | + public string? UrlFormat { get; set; } |
| 44 | + } |
| 45 | +#endif |
| 46 | +} |
0 commit comments