Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RequiresAssemblyFilesAttribute #46824

Merged
merged 2 commits into from
Jan 12, 2021
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 @@ -226,6 +226,7 @@
<Compile Include="$(MSBuildThisFileDirectory)System\Decimal.DecCalc.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\DefaultBinder.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Delegate.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\CodeAnalysis\RequiresAssemblyFilesAttribute.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\CodeAnalysis\RequiresUnreferencedCodeAttribute.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\CodeAnalysis\DynamicallyAccessedMemberTypes.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\CodeAnalysis\DynamicallyAccessedMembersAttribute.cs" />
Expand Down
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; }
}
}
7 changes: 7 additions & 0 deletions src/libraries/System.Runtime/ref/System.Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5932,6 +5932,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
{
Expand Down
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);
}
}
}