From abee17762558f6b4435163fe192c92b9caefde40 Mon Sep 17 00:00:00 2001 From: Sergei Papikian <50848091+I-SER-I@users.noreply.github.com> Date: Tue, 26 Nov 2024 20:38:21 +0300 Subject: [PATCH] feat: Add Message property to ExperimentalAttribute (#108216) Co-authored-by: Sergey Papikyan Co-authored-by: Tanner Gooding --- .../CodeAnalysis/ExperimentalAttribute.cs | 9 +++++++++ .../System.Runtime/ref/System.Runtime.cs | 1 + .../CodeAnalysis/ExperimentalAttributeTests.cs | 15 +++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/ExperimentalAttribute.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/ExperimentalAttribute.cs index 198341e3f78a6..65429998ab591 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/ExperimentalAttribute.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/ExperimentalAttribute.cs @@ -49,6 +49,15 @@ public ExperimentalAttribute(string diagnosticId) /// public string DiagnosticId { get; } + /// + /// Gets or sets an optional message associated with the experimental attribute. + /// + /// The message that provides additional information about the experimental feature. + /// + /// This message can be used to provide more context or guidance about the experimental feature. + /// + public string? Message { get; set; } + /// /// Gets or sets the URL for corresponding documentation. /// The API accepts a format string instead of an actual URL, creating a generic URL that includes the diagnostic ID. diff --git a/src/libraries/System.Runtime/ref/System.Runtime.cs b/src/libraries/System.Runtime/ref/System.Runtime.cs index e60d068cadc0f..46e4c9fc75df3 100644 --- a/src/libraries/System.Runtime/ref/System.Runtime.cs +++ b/src/libraries/System.Runtime/ref/System.Runtime.cs @@ -8913,6 +8913,7 @@ public sealed partial class ExperimentalAttribute : System.Attribute { public ExperimentalAttribute(string diagnosticId) { } public string DiagnosticId { get { throw null; } } + public string? Message { get { throw null; } set { } } public string? UrlFormat { get { throw null; } set { } } } [System.AttributeUsageAttribute(System.AttributeTargets.Property, Inherited=false, AllowMultiple=true)] diff --git a/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Diagnostics/CodeAnalysis/ExperimentalAttributeTests.cs b/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Diagnostics/CodeAnalysis/ExperimentalAttributeTests.cs index 91beaf2991fca..4088037a54ac3 100644 --- a/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Diagnostics/CodeAnalysis/ExperimentalAttributeTests.cs +++ b/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Diagnostics/CodeAnalysis/ExperimentalAttributeTests.cs @@ -36,5 +36,20 @@ public void TestSetUrlFormat(string urlFormat) Assert.Equal("diagnosticId", attr.DiagnosticId); Assert.Equal(urlFormat, attr.UrlFormat); } + + [Theory] + [InlineData(null)] + [InlineData("")] + [InlineData("This is an experimental feature")] + public void TestSetMessage(string message) + { + var attribute = new ExperimentalAttribute("diagnosticId") + { + Message = message + }; + + Assert.Equal("diagnosticId", attribute.DiagnosticId); + Assert.Equal(message, attribute.Message); + } } }