<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\RequiresDynamicCodeAttribute.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" />
--- /dev/null
+// 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 method requires the ability to generate new code at runtime,
+ /// for example through <see cref="System.Reflection"/>.
+ /// </summary>
+ /// <remarks>
+ /// This allows tools to understand which methods are unsafe to call when compiling ahead of time.
+ /// </remarks>
+ [AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor, Inherited = false)]
+ public sealed class RequiresDynamicCodeAttribute : Attribute
+ {
+ /// <summary>
+ /// Initializes a new instance of the <see cref="RequiresDynamicCodeAttribute"/> class
+ /// with the specified message.
+ /// </summary>
+ /// <param name="message">
+ /// A message that contains information about the usage of dynamic code.
+ /// </param>
+ public RequiresDynamicCodeAttribute(string message)
+ {
+ Message = message;
+ }
+
+ /// <summary>
+ /// Gets a message that contains information about the usage of dynamic code.
+ /// </summary>
+ public string Message { get; }
+
+ /// <summary>
+ /// Gets or sets an optional URL that contains more information about the method,
+ /// why it requires dynamic code, and what options a consumer has to deal with it.
+ /// </summary>
+ public string? Url { get; set; }
+ }
+}
public string? Message { get { throw null; } }
public string? Url { get { throw null; } set { } }
}
+ [System.AttributeUsageAttribute(System.AttributeTargets.Constructor | System.AttributeTargets.Method, Inherited = false)]
+ public sealed partial class RequiresDynamicCodeAttribute : System.Attribute
+ {
+ public RequiresDynamicCodeAttribute(string message) { }
+ public string Message { get { throw null; } }
+ public string? Url { get { throw null; } set { } }
+ }
[System.AttributeUsageAttribute(System.AttributeTargets.Class | System.AttributeTargets.Constructor | System.AttributeTargets.Method, Inherited=false)]
public sealed partial class RequiresUnreferencedCodeAttribute : System.Attribute
{
<Compile Include="System\DBNullTests.cs" />
<Compile Include="System\DecimalTests.cs" />
<Compile Include="System\DelegateTests.cs" />
- <Compile Include="System\Diagnostics\CodeAnalysis\DynamicDependencyAttributeTests.cs" />
<Compile Include="System\DivideByZeroExceptionTests.cs" />
<Compile Include="System\DoubleTests.cs" />
<Compile Include="System\DuplicateWaitObjectExceptionTests.cs" />
<Compile Include="System\ComponentModel\EditorBrowsableAttributeTests.cs" />
<Compile Include="System\Diagnostics\ConditionalAttributeTests.cs" />
<Compile Include="System\Diagnostics\CodeAnalysis\DynamicallyAccessedMembersAttributeTests.cs" />
+ <Compile Include="System\Diagnostics\CodeAnalysis\DynamicDependencyAttributeTests.cs" />
+ <Compile Include="System\Diagnostics\CodeAnalysis\RequiresAssemblyFilesAttributeTests.cs" />
+ <Compile Include="System\Diagnostics\CodeAnalysis\RequiresDynamicCodeAttributeTests.cs" />
<Compile Include="System\Diagnostics\CodeAnalysis\RequiresUnreferencedCodeAttributeTests.cs" />
<Compile Include="System\Diagnostics\CodeAnalysis\UnconditionalSuppressMessageAttributeTests.cs" />
<Compile Include="System\Diagnostics\StackTraceHiddenAttributeTests.cs" />
[InlineData(null)]
public void TestSetUrl(string url)
{
- var attr = new RequiresAssemblyFilesAttribute(Url = url);
+ var attr = new RequiresAssemblyFilesAttribute()
+ {
+ Url = url
+ };
Assert.Null(attr.Message);
Assert.Equal(url, attr.Url);
[InlineData(null, null)]
public void TestSetMessageAndUrl(string message, string url)
{
- var attr = new RequiresAssemblyFilesAttribute(message, Url = url);
+ var attr = new RequiresAssemblyFilesAttribute(message)
+ {
+ Url = url
+ };
Assert.Equal(message, attr.Message);
- Assert.Equal(ur, attr.Url);
+ Assert.Equal(url, attr.Url);
}
}
}
--- /dev/null
+// 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 RequiresDynamicCodeAttributeTests
+ {
+ [Fact]
+ public void TestConstructor()
+ {
+ var attr = new RequiresDynamicCodeAttribute("User Message");
+
+ Assert.Equal("User Message", attr.Message);
+ Assert.Null(attr.Url);
+ }
+
+ [Theory]
+ [InlineData("https://dot.net")]
+ [InlineData("")]
+ [InlineData(null)]
+ public void TestSetUrl(string url)
+ {
+ var attr = new RequiresDynamicCodeAttribute("User Message")
+ {
+ Url = url
+ };
+
+ Assert.Equal("User Message", attr.Message);
+ Assert.Equal(url, attr.Url);
+ }
+ }
+}