Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
}
3 changes: 3 additions & 0 deletions src/libraries/System.Runtime/ref/System.Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13612,6 +13612,9 @@ private protected OSPlatformAttribute(string platformName) { }
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")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,35 @@ public void RequiresPreviewFeaturesAttributeTest()
{
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);
}
}
}