-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add RequiresAssemblyFilesAttribute (#46824)
* Add RequiresAssemblyFilesAttribute * Apply suggestions from code review Co-authored-by: Eric Erhardt <eric.erhardt@microsoft.com>
- Loading branch information
Showing
4 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...tem.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/RequiresAssemblyFilesAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
namespace System.Diagnostics.CodeAnalysis | ||
{ | ||
/// <summary> | ||
/// Indicates that the specified member requires assembly files to be on disk. | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Constructor | | ||
AttributeTargets.Event | | ||
AttributeTargets.Method | | ||
AttributeTargets.Property, | ||
Inherited = false, | ||
AllowMultiple = false)] | ||
public sealed class RequiresAssemblyFilesAttribute : Attribute | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="RequiresAssemblyFilesAttribute"/> class. | ||
/// </summary> | ||
public RequiresAssemblyFilesAttribute() { } | ||
|
||
/// <summary> | ||
/// Gets or sets an optional message that contains information about the need for | ||
/// assembly files to be on disk. | ||
/// </summary> | ||
public string? Message { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets an optional URL that contains more information about the member, | ||
/// why it requires assembly files to be on disk, and what options a consumer has | ||
/// to deal with it. | ||
/// </summary> | ||
public string? Url { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
...stem.Runtime/tests/System/Diagnostics/CodeAnalysis/RequiresAssemblyFilesAttributeTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using Xunit; | ||
|
||
namespace System.Diagnostics.CodeAnalysis.Tests | ||
{ | ||
public class RequiresAssemblyFilesAttributeTests | ||
{ | ||
[Fact] | ||
public void TestConstructor() | ||
{ | ||
var attr = new RequiresAssemblyFilesAttribute(); | ||
|
||
Assert.Null(attr.Message); | ||
Assert.Null(attr.Url); | ||
} | ||
|
||
[Theory] | ||
[InlineData("Message")] | ||
[InlineData("")] | ||
[InlineData(null)] | ||
public void TestSetMessage(string message) | ||
{ | ||
var attr = new RequiresAssemblyFilesAttribute(Message = message); | ||
|
||
Assert.Equal(message, attr.Message); | ||
Assert.Null(attr.Url); | ||
} | ||
|
||
[Theory] | ||
[InlineData("https://dot.net")] | ||
[InlineData("")] | ||
[InlineData(null)] | ||
public void TestSetUrl(string url) | ||
{ | ||
var attr = new RequiresAssemblyFilesAttribute(Url = url); | ||
|
||
Assert.Null(attr.Message); | ||
Assert.Equal(url, attr.Url); | ||
} | ||
|
||
[Theory] | ||
[InlineData("Message", "https://dot.net")] | ||
[InlineData("Message", "")] | ||
[InlineData("Message", null)] | ||
[InlineData("", "https://dot.net")] | ||
[InlineData("", "")] | ||
[InlineData("", null)] | ||
[InlineData(null, "https://dot.net")] | ||
[InlineData(null, "")] | ||
[InlineData(null, null)] | ||
public void TestSetMessageAndUrl(string message, string url) | ||
{ | ||
var attr = new RequiresAssemblyFilesAttribute(Message = message, Url = url); | ||
|
||
Assert.Equal(message, attr.Message); | ||
Assert.Equal(ur, attr.Url); | ||
} | ||
} | ||
} |