Allow DynamicallyAccessedMembersAttribute on methods (#36340)
authorVitek Karas <vitek.karas@microsoft.com>
Fri, 29 May 2020 21:15:46 +0000 (14:15 -0700)
committerGitHub <noreply@github.com>
Fri, 29 May 2020 21:15:46 +0000 (14:15 -0700)
Allow DynamicallyAccessedMembersAttribute on methods

src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/DynamicallyAccessedMembersAttribute.cs
src/libraries/System.Runtime/ref/System.Runtime.cs

index 13d4d66..988bd01 100644 (file)
@@ -16,10 +16,15 @@ namespace System.Diagnostics.CodeAnalysis
     ///
     /// When this attribute is applied to a location of type <see cref="string"/>, the assumption is
     /// that the string represents a fully qualified type name.
+    ///
+    /// If the attribute is applied to a method it's treated as a special case and it implies
+    /// the attribute should be applied to the "this" parameter of the method. As such the attribute
+    /// should only be used on instance methods of types assignable to System.Type (or string, but no methods
+    /// will use it there).
     /// </remarks>
     [AttributeUsage(
         AttributeTargets.Field | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter |
-        AttributeTargets.Parameter | AttributeTargets.Property,
+        AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.Method,
         Inherited = false)]
     public sealed class DynamicallyAccessedMembersAttribute : Attribute
     {
index 2aac15f..275236e 100644 (file)
@@ -5628,7 +5628,7 @@ namespace System.Diagnostics.CodeAnalysis
         public string? AssemblyName { get { throw null; } }
         public string? Condition { get { throw null; } set { } }
     }
-    [System.AttributeUsageAttribute(System.AttributeTargets.Field | System.AttributeTargets.GenericParameter | System.AttributeTargets.Parameter | System.AttributeTargets.Property | System.AttributeTargets.ReturnValue, Inherited = false)]
+    [System.AttributeUsageAttribute(System.AttributeTargets.Field | System.AttributeTargets.GenericParameter | System.AttributeTargets.Method | System.AttributeTargets.Parameter | System.AttributeTargets.Property | System.AttributeTargets.ReturnValue, Inherited = false)]
     public sealed class DynamicallyAccessedMembersAttribute : System.Attribute
     {
         public DynamicallyAccessedMembersAttribute(DynamicallyAccessedMemberTypes memberTypes) { }