Skip to content
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 @@ -172,7 +172,7 @@ internal void StoreDynamicMethod(MethodInfo dynamicMethod)

// This method will combine this delegate with the passed delegate
// to form a new delegate.
protected sealed override Delegate CombineImpl(Delegate? follow)
internal new Delegate CombineImpl(Delegate? follow)
{
if (follow is null)
return this;
Expand Down Expand Up @@ -290,29 +290,29 @@ private static bool EqualInvocationLists(object[] a, object[] b, int start, int
// look at the invocation list.) If this is found we remove it from
// this list and return a new delegate. If its not found a copy of the
// current list is returned.
protected sealed override Delegate? RemoveImpl(Delegate value)
internal new Delegate? RemoveImpl(Delegate? value)
{
// There is a special case were we are removing using a delegate as
// the value we need to check for this case
//
MulticastDelegate? v = value as MulticastDelegate;

if (v == null)
return this;

if (v._invocationList is not object[])
{
if (_invocationList is not object[] invocationList)
{
// they are both not real Multicast
if (Equals(value))
if (Equals(v))
return null;
}
else
{
int invocationCount = (int)_invocationCount;
for (int i = invocationCount; --i >= 0;)
{
if (value.Equals(invocationList[i]))
if (v.Equals(invocationList[i]))
{
if (invocationCount == 2)
{
Expand Down Expand Up @@ -362,7 +362,7 @@ private static bool EqualInvocationLists(object[] a, object[] b, int start, int
}

// This method returns the Invocation list of this multicast delegate.
public sealed override Delegate[] GetInvocationList()
internal new Delegate[] GetInvocationList()
{
Delegate[] del;
if (_invocationList is not object[] invocationList)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ private static bool TrySetSlot(Wrapper[] a, int index, Delegate o)

// This method will combine this delegate with the passed delegate
// to form a new delegate.
protected virtual Delegate CombineImpl(Delegate? d)
protected Delegate CombineImpl(Delegate? d)
{
if (d is null)
return this;
Expand Down Expand Up @@ -602,7 +602,7 @@ private static bool EqualInvocationLists(Wrapper[] a, Wrapper[] b, int start, in
// look at the invocation list.) If this is found we remove it from
// this list and return a new delegate. If its not found a copy of the
// current list is returned.
protected virtual Delegate? RemoveImpl(Delegate d)
protected Delegate? RemoveImpl(Delegate? d)
{
// There is a special case were we are removing using a delegate as
// the value we need to check for this case
Expand Down Expand Up @@ -671,7 +671,7 @@ private static bool EqualInvocationLists(Wrapper[] a, Wrapper[] b, int start, in
return this;
}

public virtual Delegate[] GetInvocationList()
public Delegate[] GetInvocationList()
{
if (_helperObject is Wrapper[] invocationList)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2990,9 +2990,6 @@
<data name="MissingSatelliteAssembly_Default" xml:space="preserve">
<value>Resource lookup fell back to the ultimate fallback resources in a satellite assembly, but that satellite either was not found or could not be loaded. Please consider reinstalling or repairing the application.</value>
</data>
<data name="Multicast_Combine" xml:space="preserve">
<value>Delegates that are not of type MulticastDelegate may not be combined.</value>
</data>
<data name="MustUseCCRewrite" xml:space="preserve">
<value>An assembly (probably "{1}") must be rewritten using the code contracts binary rewriter (CCRewrite) because it is calling Contract.{0} and the CONTRACTS_FULL symbol is defined. Remove any explicit definitions of the CONTRACTS_FULL symbol from your project and rebuild. CCRewrite can be downloaded from https://go.microsoft.com/fwlink/?LinkID=169180. \r\nAfter the rewriter is installed, it can be enabled in Visual Studio from the project's Properties page on the Code Contracts pane. Ensure that "Perform Runtime Contract Checking" is enabled, which will define CONTRACTS_FULL.</value>
</data>
Expand Down
6 changes: 3 additions & 3 deletions src/libraries/System.Private.CoreLib/src/System/Delegate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ public abstract partial class Delegate : ICloneable, ISerializable
public static Delegate CreateDelegate(Type type, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.AllMethods)] Type target, string method, bool ignoreCase) => CreateDelegate(type, target, method, ignoreCase, throwOnBindFailure: true)!;

#if !NATIVEAOT
protected virtual Delegate CombineImpl(Delegate? d) => throw new MulticastNotSupportedException(SR.Multicast_Combine);
Comment thread
MichalPetryka marked this conversation as resolved.
protected Delegate CombineImpl(Delegate? d) => Unsafe.As<MulticastDelegate>(this).CombineImpl(d);

protected virtual Delegate? RemoveImpl(Delegate d) => d.Equals(this) ? null : this;
protected Delegate? RemoveImpl(Delegate? d) => Unsafe.As<MulticastDelegate>(this).RemoveImpl(d);

public virtual Delegate[] GetInvocationList() => [this];
public Delegate[] GetInvocationList() => Unsafe.As<MulticastDelegate>(this).GetInvocationList();

/// <summary>
/// Gets a value that indicates whether the <see cref="Delegate"/> has a single invocation target.
Expand Down
9 changes: 3 additions & 6 deletions src/libraries/System.Runtime/ref/System.Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2342,7 +2342,7 @@ protected Delegate([System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAt
public static System.Delegate? Combine(System.Delegate? a, System.Delegate? b) { throw null; }
public static System.Delegate? Combine(params System.Delegate?[]? delegates) { throw null; }
public static System.Delegate? Combine(params System.ReadOnlySpan<System.Delegate?> delegates) { throw null; }
protected virtual System.Delegate CombineImpl(System.Delegate? d) { throw null; }
protected System.Delegate CombineImpl(System.Delegate? d) { throw null; }
public static System.Delegate CreateDelegate(System.Type type, object? firstArgument, System.Reflection.MethodInfo method) { throw null; }
public static System.Delegate? CreateDelegate(System.Type type, object? firstArgument, System.Reflection.MethodInfo method, bool throwOnBindFailure) { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("The target method might be removed")]
Expand All @@ -2361,7 +2361,7 @@ protected Delegate([System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAt
public static System.Delegate.InvocationListEnumerator<TDelegate> EnumerateInvocationList<TDelegate>(TDelegate? d) where TDelegate : System.Delegate { throw null; }
public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; }
public override int GetHashCode() { throw null; }
public virtual System.Delegate[] GetInvocationList() { throw null; }
public System.Delegate[] GetInvocationList() { throw null; }
protected virtual System.Reflection.MethodInfo GetMethodImpl() { throw null; }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
[System.ObsoleteAttribute("This API supports obsolete formatter-based serialization. It should not be called or extended by application code.", DiagnosticId="SYSLIB0051", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
Expand All @@ -2370,7 +2370,7 @@ public virtual void GetObjectData(System.Runtime.Serialization.SerializationInfo
public static bool operator !=(System.Delegate? d1, System.Delegate? d2) { throw null; }
public static System.Delegate? Remove(System.Delegate? source, System.Delegate? value) { throw null; }
public static System.Delegate? RemoveAll(System.Delegate? source, System.Delegate? value) { throw null; }
protected virtual System.Delegate? RemoveImpl(System.Delegate d) { throw null; }
protected System.Delegate? RemoveImpl(System.Delegate? d) { throw null; }
public partial struct InvocationListEnumerator<TDelegate> where TDelegate : System.Delegate
{
public TDelegate Current { get { throw null; } }
Expand Down Expand Up @@ -4793,17 +4793,14 @@ 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)) { }
protected MulticastDelegate([System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.AllMethods)] 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([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; }
public sealed override int GetHashCode() { throw null; }
public sealed override System.Delegate[] GetInvocationList() { throw null; }
protected override System.Reflection.MethodInfo GetMethodImpl() { throw null; }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
[System.ObsoleteAttribute("This API supports obsolete formatter-based serialization. It should not be called or extended by application code.", DiagnosticId="SYSLIB0051", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
public override void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { }
public static bool operator ==(System.MulticastDelegate? d1, System.MulticastDelegate? d2) { throw null; }
public static bool operator !=(System.MulticastDelegate? d1, System.MulticastDelegate? d2) { throw null; }
protected sealed override System.Delegate? RemoveImpl(System.Delegate value) { throw null; }
}
public sealed partial class MulticastNotSupportedException : System.SystemException
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,60 @@
<Left>net10.0/System.Runtime.Intrinsics.dll</Left>
<Right>net11.0/System.Runtime.Intrinsics.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0012</DiagnosticId>
<Target>M:System.Delegate.CombineImpl(System.Delegate)</Target>
<Left>net10.0/mscorlib.dll</Left>
<Right>net11.0/mscorlib.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0012</DiagnosticId>
<Target>M:System.Delegate.GetInvocationList</Target>
<Left>net10.0/mscorlib.dll</Left>
<Right>net11.0/mscorlib.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0012</DiagnosticId>
<Target>M:System.Delegate.RemoveImpl(System.Delegate)</Target>
<Left>net10.0/mscorlib.dll</Left>
<Right>net11.0/mscorlib.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0012</DiagnosticId>
<Target>M:System.Delegate.CombineImpl(System.Delegate)</Target>
<Left>net10.0/netstandard.dll</Left>
<Right>net11.0/netstandard.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0012</DiagnosticId>
<Target>M:System.Delegate.GetInvocationList</Target>
<Left>net10.0/netstandard.dll</Left>
<Right>net11.0/netstandard.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0012</DiagnosticId>
<Target>M:System.Delegate.RemoveImpl(System.Delegate)</Target>
<Left>net10.0/netstandard.dll</Left>
<Right>net11.0/netstandard.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0012</DiagnosticId>
<Target>M:System.Delegate.CombineImpl(System.Delegate)</Target>
<Left>net10.0/System.Runtime.dll</Left>
<Right>net11.0/System.Runtime.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0012</DiagnosticId>
<Target>M:System.Delegate.GetInvocationList</Target>
<Left>net10.0/System.Runtime.dll</Left>
<Right>net11.0/System.Runtime.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0012</DiagnosticId>
<Target>M:System.Delegate.RemoveImpl(System.Delegate)</Target>
<Left>net10.0/System.Runtime.dll</Left>
<Right>net11.0/System.Runtime.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0014</DiagnosticId>
<Target>M:System.Security.Cryptography.X509Certificates.PublicKey.#ctor(System.Security.Cryptography.MLDsa):[T:System.Diagnostics.CodeAnalysis.ExperimentalAttribute]</Target>
Expand Down
56 changes: 55 additions & 1 deletion src/libraries/apicompat/ApiCompatBaseline.netstandard2.0.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<!-- https://learn.microsoft.com/dotnet/fundamentals/package-validation/diagnostic-ids -->
<Suppressions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Suppression>
Expand Down Expand Up @@ -229,6 +229,60 @@
<Left>netstandard2.0/System.Xml.dll</Left>
<Right>net11.0/System.Xml.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0012</DiagnosticId>
<Target>M:System.Delegate.CombineImpl(System.Delegate)</Target>
<Left>netstandard2.0/mscorlib.dll</Left>
<Right>net11.0/mscorlib.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0012</DiagnosticId>
<Target>M:System.Delegate.GetInvocationList</Target>
<Left>netstandard2.0/mscorlib.dll</Left>
<Right>net11.0/mscorlib.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0012</DiagnosticId>
<Target>M:System.Delegate.RemoveImpl(System.Delegate)</Target>
<Left>netstandard2.0/mscorlib.dll</Left>
<Right>net11.0/mscorlib.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0012</DiagnosticId>
<Target>M:System.Delegate.CombineImpl(System.Delegate)</Target>
<Left>netstandard2.0/netstandard.dll</Left>
<Right>net11.0/netstandard.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0012</DiagnosticId>
<Target>M:System.Delegate.GetInvocationList</Target>
<Left>netstandard2.0/netstandard.dll</Left>
<Right>net11.0/netstandard.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0012</DiagnosticId>
<Target>M:System.Delegate.RemoveImpl(System.Delegate)</Target>
<Left>netstandard2.0/netstandard.dll</Left>
<Right>net11.0/netstandard.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0012</DiagnosticId>
<Target>M:System.Delegate.CombineImpl(System.Delegate)</Target>
<Left>netstandard2.0/System.Runtime.dll</Left>
<Right>net11.0/System.Runtime.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0012</DiagnosticId>
<Target>M:System.Delegate.GetInvocationList</Target>
<Left>netstandard2.0/System.Runtime.dll</Left>
<Right>net11.0/System.Runtime.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0012</DiagnosticId>
<Target>M:System.Delegate.RemoveImpl(System.Delegate)</Target>
<Left>netstandard2.0/System.Runtime.dll</Left>
<Right>net11.0/System.Runtime.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0014</DiagnosticId>
<Target>M:System.Collections.IEnumerable.GetEnumerator:[T:System.Runtime.InteropServices.DispIdAttribute]</Target>
Expand Down
32 changes: 25 additions & 7 deletions src/libraries/apicompat/ApiCompatBaseline.netstandard2.1.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<!-- https://learn.microsoft.com/dotnet/fundamentals/package-validation/diagnostic-ids -->
<Suppressions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Suppression>
<DiagnosticId>CP0012</DiagnosticId>
<Target>M:System.Delegate.CombineImpl(System.Delegate)</Target>
<Left>netstandard2.1/netstandard.dll</Left>
<Right>net11.0/netstandard.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0012</DiagnosticId>
<Target>M:System.Delegate.GetInvocationList</Target>
<Left>netstandard2.1/netstandard.dll</Left>
<Right>net11.0/netstandard.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0012</DiagnosticId>
<Target>M:System.Delegate.RemoveImpl(System.Delegate)</Target>
<Left>netstandard2.1/netstandard.dll</Left>
<Right>net11.0/netstandard.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0014</DiagnosticId>
<Target>E:System.Diagnostics.Process.ErrorDataReceived:[T:System.ComponentModel.BrowsableAttribute]</Target>
Expand Down Expand Up @@ -853,6 +871,12 @@
<Left>netstandard2.1/netstandard.dll</Left>
<Right>net11.0/netstandard.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0015</DiagnosticId>
<Target>T:System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute:[T:System.AttributeUsageAttribute]</Target>
<Left>netstandard2.1/netstandard.dll</Left>
<Right>net11.0/netstandard.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0015</DiagnosticId>
<Target>T:System.Runtime.CompilerServices.AsyncMethodBuilderAttribute:[T:System.AttributeUsageAttribute]</Target>
Expand Down Expand Up @@ -1003,10 +1027,4 @@
<Left>netstandard2.1/netstandard.dll</Left>
<Right>net11.0/netstandard.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0015</DiagnosticId>
<Target>T:System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute:[T:System.AttributeUsageAttribute]</Target>
<Left>netstandard2.1/netstandard.dll</Left>
<Right>net11.0/netstandard.dll</Right>
</Suppression>
</Suppressions>
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ protected override MethodInfo GetMethodImpl()
// Return, in order of invocation, the invocation list
// of a MulticastDelegate
// </summary>
public sealed override Delegate[] GetInvocationList()
internal new Delegate[] GetInvocationList()
{
if (delegates != null)
return (Delegate[])delegates.Clone();
Expand Down Expand Up @@ -126,7 +126,7 @@ public sealed override Delegate[] GetInvocationList()
// thing should have better been a simple System.Delegate class.
// Compiler generated delegates are always MulticastDelegates.
// </summary>
protected sealed override Delegate CombineImpl(Delegate? follow)
internal new Delegate CombineImpl(Delegate? follow)
{
if (follow == null)
return this;
Expand Down Expand Up @@ -197,7 +197,7 @@ private static int LastIndexOf(Delegate[] haystack, Delegate[] needle)
return -1;
}

protected sealed override Delegate? RemoveImpl(Delegate value)
internal new Delegate? RemoveImpl(Delegate? value)
{
if (value == null)
return this;
Expand Down
Loading