Skip to content

Commit 822d877

Browse files
author
Prashanth Govindarajan
authored
Update RequiresPreviewFeatures attribute (#56938)
* Add constructors and Message, URL properties * Update attribute and tests * sq * Address feedback * Just adding docs
1 parent 3db6ec5 commit 822d877

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

src/libraries/System.Private.CoreLib/src/System/Runtime/Versioning/RequiresPreviewFeaturesAttribute.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,28 @@ namespace System.Runtime.Versioning
1717
AttributeTargets.Event, Inherited = false)]
1818
public sealed class RequiresPreviewFeaturesAttribute : Attribute
1919
{
20+
/// <summary>
21+
/// Initializes a new instance of the <seealso cref="RequiresPreviewFeaturesAttribute"/> class.
22+
/// </summary>
2023
public RequiresPreviewFeaturesAttribute() { }
24+
25+
/// <summary>
26+
/// Initializes a new instance of the <seealso cref="RequiresPreviewFeaturesAttribute"/> class with the specified message.
27+
/// </summary>
28+
/// <param name="message">An optional message associated with this attribute instance.</param>
29+
public RequiresPreviewFeaturesAttribute(string? message)
30+
{
31+
Message = message;
32+
}
33+
34+
/// <summary>
35+
/// Returns the optional message associated with this attribute instance.
36+
/// </summary>
37+
public string? Message { get; }
38+
39+
/// <summary>
40+
/// Returns the optional URL associated with this attribute instance.
41+
/// </summary>
42+
public string? Url { get; set; }
2143
}
2244
}

src/libraries/System.Runtime/ref/System.Runtime.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13612,6 +13612,9 @@ private protected OSPlatformAttribute(string platformName) { }
1361213612
public sealed partial class RequiresPreviewFeaturesAttribute : System.Attribute
1361313613
{
1361413614
public RequiresPreviewFeaturesAttribute() { }
13615+
public RequiresPreviewFeaturesAttribute(string? message) { }
13616+
public string? Message { get { throw null; } }
13617+
public string? Url { get { throw null; } set { } }
1361513618
}
1361613619
[System.AttributeUsageAttribute(System.AttributeTargets.Constructor | System.AttributeTargets.Method | System.AttributeTargets.Property, Inherited=false)]
1361713620
[System.Diagnostics.ConditionalAttribute("RESOURCE_ANNOTATION_WORK")]

src/libraries/System.Runtime/tests/System/Runtime/Versioning/RequiresPreviewFeaturesAttributeTests.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,35 @@ public void RequiresPreviewFeaturesAttributeTest()
1212
{
1313
new RequiresPreviewFeaturesAttribute();
1414
}
15+
16+
[Fact]
17+
public static void Ctor_Default()
18+
{
19+
var attribute = new RequiresPreviewFeaturesAttribute();
20+
Assert.Null(attribute.Message);
21+
Assert.Null(attribute.Url);
22+
}
23+
24+
[Theory]
25+
[InlineData(null)]
26+
[InlineData("")]
27+
[InlineData("message")]
28+
public void Ctor_String_Message(string message)
29+
{
30+
var attribute = new RequiresPreviewFeaturesAttribute(message);
31+
Assert.Same(message, attribute.Message);
32+
Assert.Null(attribute.Url);
33+
}
34+
35+
[Theory]
36+
[InlineData(null, "")]
37+
[InlineData("", null)]
38+
[InlineData("message", "https://aka.ms/preview-features/")]
39+
public void Ctor_String_Url(string message, string url)
40+
{
41+
var attribute = new RequiresPreviewFeaturesAttribute(message) { Url = url };
42+
Assert.Same(message, attribute.Message);
43+
Assert.Same(url, attribute.Url);
44+
}
1545
}
1646
}

0 commit comments

Comments
 (0)