diff --git a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems index af8dac2c313745..a980c2ff7f32d5 100644 --- a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems +++ b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems @@ -226,6 +226,7 @@ + diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/RequiresAssemblyFilesAttribute.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/RequiresAssemblyFilesAttribute.cs new file mode 100644 index 00000000000000..2b7bbcb6b9952b --- /dev/null +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/RequiresAssemblyFilesAttribute.cs @@ -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 +{ + /// + /// Indicates that the specified member requires assembly files to be on disk. + /// + [AttributeUsage(AttributeTargets.Constructor | + AttributeTargets.Event | + AttributeTargets.Method | + AttributeTargets.Property, + Inherited = false, + AllowMultiple = false)] + public sealed class RequiresAssemblyFilesAttribute : Attribute + { + /// + /// Initializes a new instance of the class. + /// + public RequiresAssemblyFilesAttribute() { } + + /// + /// Gets or sets an optional message that contains information about the need for + /// assembly files to be on disk. + /// + public string? Message { get; set; } + + /// + /// 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. + /// + public string? Url { get; set; } + } +} \ No newline at end of file diff --git a/src/libraries/System.Runtime/ref/System.Runtime.cs b/src/libraries/System.Runtime/ref/System.Runtime.cs index d9c3895662e3c8..061044b871ea42 100644 --- a/src/libraries/System.Runtime/ref/System.Runtime.cs +++ b/src/libraries/System.Runtime/ref/System.Runtime.cs @@ -5959,6 +5959,13 @@ public sealed partial class NotNullWhenAttribute : System.Attribute public NotNullWhenAttribute(bool returnValue) { } public bool ReturnValue { get { throw null; } } } + [System.AttributeUsageAttribute(System.AttributeTargets.Constructor | System.AttributeTargets.Event | System.AttributeTargets.Method | System.AttributeTargets.Property, Inherited = false, AllowMultiple = false)] + public sealed partial class RequiresAssemblyFilesAttribute : System.Attribute + { + public RequiresAssemblyFilesAttribute() { } + public string? Message { get { throw null; } set { } } + public string? Url { get { throw null; } set { } } + } [System.AttributeUsageAttribute(System.AttributeTargets.Constructor | System.AttributeTargets.Method, Inherited=false)] public sealed partial class RequiresUnreferencedCodeAttribute : System.Attribute { diff --git a/src/libraries/System.Runtime/tests/System/Diagnostics/CodeAnalysis/RequiresAssemblyFilesAttributeTests.cs b/src/libraries/System.Runtime/tests/System/Diagnostics/CodeAnalysis/RequiresAssemblyFilesAttributeTests.cs new file mode 100644 index 00000000000000..da098f97f5ad6f --- /dev/null +++ b/src/libraries/System.Runtime/tests/System/Diagnostics/CodeAnalysis/RequiresAssemblyFilesAttributeTests.cs @@ -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); + } + } +}