Update RequiresPreviewFeatures attribute (#56938)
authorPrashanth Govindarajan <prgovi@microsoft.com>
Mon, 9 Aug 2021 22:48:40 +0000 (15:48 -0700)
committerGitHub <noreply@github.com>
Mon, 9 Aug 2021 22:48:40 +0000 (15:48 -0700)
* Add constructors and Message, URL properties

* Update attribute and tests

* sq

* Address feedback

* Just adding docs

src/libraries/System.Private.CoreLib/src/System/Runtime/Versioning/RequiresPreviewFeaturesAttribute.cs
src/libraries/System.Runtime/ref/System.Runtime.cs
src/libraries/System.Runtime/tests/System/Runtime/Versioning/RequiresPreviewFeaturesAttributeTests.cs

index 173ac200d440fe896ab0f1f93a0cf2c8a2508151..7ccea51e0c2823f0aa20e43eae8b0f86935a1629 100644 (file)
@@ -17,6 +17,28 @@ namespace System.Runtime.Versioning
                 AttributeTargets.Event, Inherited = false)]
     public sealed class RequiresPreviewFeaturesAttribute : Attribute
     {
+        /// <summary>
+        /// Initializes a new instance of the <seealso cref="RequiresPreviewFeaturesAttribute"/> class.
+        /// </summary>
         public RequiresPreviewFeaturesAttribute() { }
+
+        /// <summary>
+        /// Initializes a new instance of the <seealso cref="RequiresPreviewFeaturesAttribute"/> class with the specified message.
+        /// </summary>
+        /// <param name="message">An optional message associated with this attribute instance.</param>
+        public RequiresPreviewFeaturesAttribute(string? message)
+        {
+            Message = message;
+        }
+
+        /// <summary>
+        /// Returns the optional message associated with this attribute instance.
+        /// </summary>
+        public string? Message { get; }
+
+        /// <summary>
+        /// Returns the optional URL associated with this attribute instance.
+        /// </summary>
+        public string? Url { get; set; }
     }
 }
index 38bf0b19778cd2cbac378add5d534d78d466fbd0..1bd3d5fdbbc0ceb1ecdae38e0d83c2280b499ea1 100644 (file)
@@ -13612,6 +13612,9 @@ namespace System.Runtime.Versioning
     public sealed partial class RequiresPreviewFeaturesAttribute : System.Attribute
     {
         public RequiresPreviewFeaturesAttribute() { }
+        public RequiresPreviewFeaturesAttribute(string? message) { }
+        public string? Message { get { throw null; } }
+        public string? Url { get { throw null; } set { } }
     }
     [System.AttributeUsageAttribute(System.AttributeTargets.Constructor | System.AttributeTargets.Method | System.AttributeTargets.Property, Inherited=false)]
     [System.Diagnostics.ConditionalAttribute("RESOURCE_ANNOTATION_WORK")]
index a0ae548a72272654cdd50f7cb2ba7b3d9db1bdba..1751b90a576905fbef66afa55323750ad0886246 100644 (file)
@@ -12,5 +12,35 @@ namespace System.Runtime.Versioning.Tests
         {
             new RequiresPreviewFeaturesAttribute();
         }
+
+        [Fact]
+        public static void Ctor_Default()
+        {
+            var attribute = new RequiresPreviewFeaturesAttribute();
+            Assert.Null(attribute.Message);
+            Assert.Null(attribute.Url);
+        }
+
+        [Theory]
+        [InlineData(null)]
+        [InlineData("")]
+        [InlineData("message")]
+        public void Ctor_String_Message(string message)
+        {
+            var attribute = new RequiresPreviewFeaturesAttribute(message);
+            Assert.Same(message, attribute.Message);
+            Assert.Null(attribute.Url);
+        }
+
+        [Theory]
+        [InlineData(null, "")]
+        [InlineData("", null)]
+        [InlineData("message", "https://aka.ms/preview-features/")]
+        public void Ctor_String_Url(string message, string url)
+        {
+            var attribute = new RequiresPreviewFeaturesAttribute(message) { Url = url };
+            Assert.Same(message, attribute.Message);
+            Assert.Same(url, attribute.Url);
+        }
     }
 }