Skip to content

Commit

Permalink
Add RequiresUnreferencedCode to Delegate constructors
Browse files Browse the repository at this point in the history
Contributes to dotnet#45623
  • Loading branch information
eerhardt committed Dec 14, 2020
1 parent 296aaf8 commit de3a322
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public abstract partial class Delegate : ICloneable, ISerializable

// This constructor is called from the class generated by the
// compiler generated code
[RequiresUnreferencedCode("The target method might be removed")]
protected Delegate(object target, string method)
{
if (target == null)
Expand All @@ -56,6 +57,7 @@ protected Delegate(object target, string method)
// This constructor is called from a class to generate a
// delegate based upon a static method name and the Type object
// for the class defining the method.
[RequiresUnreferencedCode("The target method might be removed")]
protected Delegate(Type target, string method)
{
if (target == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ public abstract class MulticastDelegate : Delegate
// This constructor is called from the class generated by the
// compiler generated code (This must match the constructor
// in Delegate
[RequiresUnreferencedCode("The target method might be removed")]
protected MulticastDelegate(object target, string method) : base(target, method)
{
}

// This constructor is called from a class to generate a
// delegate based upon a static method name and the Type object
// for the class defining the method.
[RequiresUnreferencedCode("The target method might be removed")]
protected MulticastDelegate(Type target, string method) : base(target, method)
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,6 @@
<property name="Scope">member</property>
<property name="Target">M:Internal.Runtime.InteropServices.IsolatedComponentLoadContext.Load(System.Reflection.AssemblyName)</property>
</attribute>
<attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
<argument>ILLink</argument>
<argument>IL2026</argument>
<property name="Scope">member</property>
<property name="Target">M:System.Delegate.#ctor(System.Object,System.String)</property>
</attribute>
<attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
<argument>ILLink</argument>
<argument>IL2026</argument>
<property name="Scope">member</property>
<property name="Target">M:System.Delegate.#ctor(System.Type,System.String)</property>
</attribute>
<attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
<argument>ILLink</argument>
<argument>IL2026</argument>
Expand Down
4 changes: 4 additions & 0 deletions src/libraries/System.Runtime/ref/System.Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1691,7 +1691,9 @@ void System.Runtime.Serialization.ISerializable.GetObjectData(System.Runtime.Ser
}
public abstract partial class Delegate : System.ICloneable, System.Runtime.Serialization.ISerializable
{
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("The target method might be removed")]
protected Delegate(object target, string method) { }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("The target method might be removed")]
protected Delegate(System.Type target, string method) { }
public System.Reflection.MethodInfo Method { get { throw null; } }
public object? Target { get { throw null; } }
Expand Down Expand Up @@ -2933,7 +2935,9 @@ public MTAThreadAttribute() { }
}
public abstract partial class MulticastDelegate : System.Delegate
{
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("The target method might be removed")]
protected MulticastDelegate(object target, string method) : base (default(object), default(string)) { }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("The target method might be removed")]
protected MulticastDelegate(System.Type target, string method) : base (default(object), default(string)) { }
protected sealed override System.Delegate CombineImpl(System.Delegate? follow) { throw null; }
public sealed override bool Equals(object? obj) { throw null; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public partial class Delegate
private bool method_is_virtual;
#endregion

[RequiresUnreferencedCode("The target method might be removed")]
protected Delegate(object target, string method)
{
if (target is null)
Expand All @@ -86,6 +87,7 @@ protected Delegate(object target, string method)
};
}

[RequiresUnreferencedCode("The target method might be removed")]
protected Delegate(Type target, string method)
{
if (target is null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ public abstract class MulticastDelegate : Delegate
{
private Delegate[]? delegates;

[RequiresUnreferencedCode("The target method might be removed")]
protected MulticastDelegate(object target, string method)
: base(target, method)
{
}

[RequiresUnreferencedCode("The target method might be removed")]
protected MulticastDelegate(Type target, string method)
: base(target, method)
{
Expand Down

0 comments on commit de3a322

Please sign in to comment.