14 [__DynamicallyInvokable]
18 private object _invocationList;
21 private IntPtr _invocationCount;
28 : base(target, method)
37 : base(target, method)
41 [SecuritySafeCritical]
42 internal bool IsUnmanagedFunctionPtr()
44 return _invocationCount == (
IntPtr)(-1);
47 [SecuritySafeCritical]
48 internal bool InvocationListLogicallyNull()
50 if (_invocationList !=
null && !(_invocationList is LoaderAllocator))
52 return _invocationList is DynamicResolver;
68 object[] array = _invocationList as
object[];
72 if (!(method is RuntimeMethodInfo) || IsUnmanagedFunctionPtr())
76 if (!InvocationListLogicallyNull() && !_invocationCount.IsNull() && !_methodPtrAux.IsNull())
80 DelegateSerializationHolder.GetDelegateSerializationInfo(info, GetType(), base.Target, method, num);
83 DelegateSerializationHolder.DelegateEntry delegateEntry =
null;
84 int num2 = (int)_invocationCount;
90 if (method2 is RuntimeMethodInfo && !IsUnmanagedFunctionPtr() && (multicastDelegate.InvocationListLogicallyNull() || multicastDelegate._invocationCount.IsNull() || multicastDelegate._methodPtrAux.IsNull()))
92 DelegateSerializationHolder.DelegateEntry delegateSerializationInfo = DelegateSerializationHolder.GetDelegateSerializationInfo(info, multicastDelegate.GetType(), multicastDelegate.
Target, method2, num++);
93 if (delegateEntry !=
null)
95 delegateEntry.Entry = delegateSerializationInfo;
97 delegateEntry = delegateSerializationInfo;
100 if (delegateEntry !=
null)
112 [SecuritySafeCritical]
113 [__DynamicallyInvokable]
114 public sealed
override bool Equals(
object obj)
116 if (obj ==
null || !
Delegate.InternalEqualTypes(
this, obj))
121 if ((
object)multicastDelegate ==
null)
125 if (_invocationCount != (
IntPtr)0)
127 if (InvocationListLogicallyNull())
129 if (IsUnmanagedFunctionPtr())
131 if (!multicastDelegate.IsUnmanagedFunctionPtr())
135 return Delegate.CompareUnmanagedFunctionPtrs(
this, multicastDelegate);
137 if (multicastDelegate._invocationList is
Delegate)
139 return Equals(multicastDelegate._invocationList);
141 return base.Equals(obj);
145 return _invocationList.Equals(obj);
147 return InvocationListEquals(multicastDelegate);
149 if (!InvocationListLogicallyNull())
151 if (!_invocationList.Equals(multicastDelegate._invocationList))
155 return base.Equals((
object)multicastDelegate);
157 if (multicastDelegate._invocationList is
Delegate)
159 return Equals(multicastDelegate._invocationList);
161 return base.Equals((
object)multicastDelegate);
164 [SecuritySafeCritical]
167 object[] array = _invocationList as
object[];
168 if (d._invocationCount != _invocationCount)
172 int num = (int)_invocationCount;
173 for (
int i = 0; i < num; i++)
175 Delegate @delegate = (Delegate)array[i];
176 object[] array2 = d._invocationList as
object[];
177 if (!@delegate.Equals(array2[i]))
186 private bool TrySetSlot(
object[] a,
int index,
object o)
192 if (a[index] !=
null)
196 if (multicastDelegate2._methodPtr == multicastDelegate._methodPtr && multicastDelegate2._target == multicastDelegate._target && multicastDelegate2._methodPtrAux == multicastDelegate._methodPtrAux)
205 private MulticastDelegate NewMulticastDelegate(
object[] invocationList,
int invocationCount,
bool thisIsMultiCastAlready)
208 if (thisIsMultiCastAlready)
210 multicastDelegate._methodPtr = _methodPtr;
211 multicastDelegate._methodPtrAux = _methodPtrAux;
215 multicastDelegate._methodPtr = GetMulticastInvoke();
216 multicastDelegate._methodPtrAux = GetInvokeMethod();
218 multicastDelegate._target = multicastDelegate;
219 multicastDelegate._invocationList = invocationList;
220 multicastDelegate._invocationCount = (IntPtr)invocationCount;
221 return multicastDelegate;
225 internal MulticastDelegate NewMulticastDelegate(
object[] invocationList,
int invocationCount)
227 return NewMulticastDelegate(invocationList, invocationCount, thisIsMultiCastAlready:
false);
231 internal void StoreDynamicMethod(
MethodInfo dynamicMethod)
233 if (_invocationCount != (IntPtr)0)
236 multicastDelegate._methodBase = dynamicMethod;
240 _methodBase = dynamicMethod;
250 [SecuritySafeCritical]
253 if ((
object)follow ==
null)
257 if (!
Delegate.InternalEqualTypes(
this, follow))
263 object[] array = multicastDelegate._invocationList as
object[];
266 num = (int)multicastDelegate._invocationCount;
268 object[] array2 = _invocationList as
object[];
274 array3 =
new object[num2];
278 array3[1] = multicastDelegate;
282 for (
int i = 0; i < num; i++)
284 array3[1 + i] = array[i];
287 return NewMulticastDelegate(array3, num2);
289 int num3 = (int)_invocationCount;
292 if (num2 <= array2.Length)
297 if (!TrySetSlot(array3, num3, multicastDelegate))
304 for (
int j = 0; j < num; j++)
306 if (!TrySetSlot(array3, num3 + j, array[j]))
317 for (num4 = array2.Length; num4 < num2; num4 *= 2)
320 array3 =
new object[num4];
321 for (
int k = 0; k < num3; k++)
323 array3[k] = array2[k];
327 array3[num3] = multicastDelegate;
331 for (
int l = 0; l < num; l++)
333 array3[num3 + l] = array[l];
337 return NewMulticastDelegate(array3, num2, thisIsMultiCastAlready:
true);
341 private object[] DeleteFromInvocationList(
object[] invocationList,
int invocationCount,
int deleteIndex,
int deleteCount)
343 object[] array = _invocationList as
object[];
344 int num = array.Length;
345 while (num / 2 >= invocationCount - deleteCount)
349 object[] array2 =
new object[num];
350 for (
int i = 0; i < deleteIndex; i++)
352 array2[i] = invocationList[i];
354 for (
int j = deleteIndex + deleteCount; j < invocationCount; j++)
356 array2[j - deleteCount] = invocationList[j];
361 private bool EqualInvocationLists(
object[] a,
object[] b,
int start,
int count)
363 for (
int i = 0; i < count; i++)
365 if (!a[start + i].
Equals(b[i]))
377 [SecuritySafeCritical]
381 if ((
object)multicastDelegate ==
null)
385 if (!(multicastDelegate._invocationList is
object[]))
387 object[] array = _invocationList as
object[];
397 int num = (int)_invocationCount;
401 if (value.Equals(array[num2]))
407 object[] invocationList = DeleteFromInvocationList(array, num, num2, 1);
408 return NewMulticastDelegate(invocationList, num - 1, thisIsMultiCastAlready:
true);
415 object[] array2 = _invocationList as
object[];
418 int num3 = (int)_invocationCount;
419 int num4 = (int)multicastDelegate._invocationCount;
420 for (
int num5 = num3 - num4; num5 >= 0; num5--)
422 if (EqualInvocationLists(array2, multicastDelegate._invocationList as
object[], num5, num4))
424 if (num3 - num4 == 0)
428 if (num3 - num4 == 1)
430 return (
Delegate)array2[(num5 == 0) ? (num3 - 1) : 0];
432 object[] invocationList2 = DeleteFromInvocationList(array2, num3, num5, num4);
433 return NewMulticastDelegate(invocationList2, num3 - num4, thisIsMultiCastAlready:
true);
444 [SecuritySafeCritical]
445 [__DynamicallyInvokable]
448 object[] array = _invocationList as
object[];
459 int num = (int)_invocationCount;
461 for (
int i = 0; i < num; i++)
475 [__DynamicallyInvokable]
478 return d1?.
Equals(d2) ?? ((object)d2 ==
null);
487 [__DynamicallyInvokable]
490 if ((
object)d1 ==
null)
492 return (
object)d2 !=
null;
500 [SecuritySafeCritical]
501 [__DynamicallyInvokable]
504 if (IsUnmanagedFunctionPtr())
506 return ValueType.GetHashCodeOfPtr(_methodPtr) ^
ValueType.GetHashCodeOfPtr(_methodPtrAux);
508 object[] array = _invocationList as
object[];
511 return base.GetHashCode();
514 for (
int i = 0; i < (int)_invocationCount; i++)
516 num = num * 33 + array[i].GetHashCode();
521 [SecuritySafeCritical]
522 internal override object GetTarget()
524 if (_invocationCount != (
IntPtr)0)
526 if (InvocationListLogicallyNull())
530 object[] array = _invocationList as
object[];
533 int num = (int)_invocationCount;
534 return ((Delegate)array[num - 1]).GetTarget();
537 if ((
object)@delegate !=
null)
539 return @delegate.GetTarget();
542 return base.GetTarget();
547 [SecuritySafeCritical]
550 if (_invocationCount != (
IntPtr)0 && _invocationList !=
null)
552 object[] array = _invocationList as
object[];
555 int num = (int)_invocationCount - 1;
559 if ((
object)multicastDelegate !=
null)
564 else if (IsUnmanagedFunctionPtr())
566 if (_methodBase ==
null || !(_methodBase is
MethodInfo))
568 IRuntimeMethodInfo runtimeMethodInfo = FindMethodHandle();
572 RuntimeType runtimeType2 = GetType() as RuntimeType;
573 runtimeType = runtimeType2;
575 _methodBase = (
MethodInfo)RuntimeType.GetMethodBase(runtimeType, runtimeMethodInfo);
579 return base.GetMethodImpl();
582 [DebuggerNonUserCode]
583 private void ThrowNullThisInDelegateToInstance()
589 [DebuggerNonUserCode]
590 private void CtorClosed(
object target, IntPtr methodPtr)
594 ThrowNullThisInDelegateToInstance();
597 _methodPtr = methodPtr;
601 [DebuggerNonUserCode]
602 private void CtorClosedStatic(
object target, IntPtr methodPtr)
605 _methodPtr = methodPtr;
609 [DebuggerNonUserCode]
610 private void CtorRTClosed(
object target, IntPtr methodPtr)
613 _methodPtr = AdjustTarget(target, methodPtr);
617 [DebuggerNonUserCode]
618 private void CtorOpened(
object target, IntPtr methodPtr, IntPtr shuffleThunk)
621 _methodPtr = shuffleThunk;
622 _methodPtrAux = methodPtr;
626 [DebuggerNonUserCode]
627 private void CtorSecureClosed(
object target, IntPtr methodPtr, IntPtr callThunk, IntPtr creatorMethod)
630 multicastDelegate.CtorClosed(target, methodPtr);
631 _invocationList = multicastDelegate;
633 _methodPtr = callThunk;
634 _methodPtrAux = creatorMethod;
635 _invocationCount = GetInvokeMethod();
639 [DebuggerNonUserCode]
640 private void CtorSecureClosedStatic(
object target, IntPtr methodPtr, IntPtr callThunk, IntPtr creatorMethod)
643 multicastDelegate.CtorClosedStatic(target, methodPtr);
644 _invocationList = multicastDelegate;
646 _methodPtr = callThunk;
647 _methodPtrAux = creatorMethod;
648 _invocationCount = GetInvokeMethod();
652 [DebuggerNonUserCode]
653 private void CtorSecureRTClosed(
object target, IntPtr methodPtr, IntPtr callThunk, IntPtr creatorMethod)
656 multicastDelegate.CtorRTClosed(target, methodPtr);
657 _invocationList = multicastDelegate;
659 _methodPtr = callThunk;
660 _methodPtrAux = creatorMethod;
661 _invocationCount = GetInvokeMethod();
665 [DebuggerNonUserCode]
666 private void CtorSecureOpened(
object target, IntPtr methodPtr, IntPtr shuffleThunk, IntPtr callThunk, IntPtr creatorMethod)
669 multicastDelegate.CtorOpened(target, methodPtr, shuffleThunk);
670 _invocationList = multicastDelegate;
672 _methodPtr = callThunk;
673 _methodPtrAux = creatorMethod;
674 _invocationCount = GetInvokeMethod();
678 [DebuggerNonUserCode]
679 private void CtorVirtualDispatch(
object target, IntPtr methodPtr, IntPtr shuffleThunk)
682 _methodPtr = shuffleThunk;
683 _methodPtrAux = GetCallStub(methodPtr);
687 [DebuggerNonUserCode]
688 private void CtorSecureVirtualDispatch(
object target, IntPtr methodPtr, IntPtr shuffleThunk, IntPtr callThunk, IntPtr creatorMethod)
691 multicastDelegate.CtorVirtualDispatch(target, methodPtr, shuffleThunk);
692 _invocationList = multicastDelegate;
694 _methodPtr = callThunk;
695 _methodPtrAux = creatorMethod;
696 _invocationCount = GetInvokeMethod();
700 [DebuggerNonUserCode]
701 private void CtorCollectibleClosedStatic(
object target, IntPtr methodPtr, IntPtr gchandle)
704 _methodPtr = methodPtr;
705 _methodBase =
GCHandle.InternalGet(gchandle);
709 [DebuggerNonUserCode]
710 private void CtorCollectibleOpened(
object target, IntPtr methodPtr, IntPtr shuffleThunk, IntPtr gchandle)
713 _methodPtr = shuffleThunk;
714 _methodPtrAux = methodPtr;
715 _methodBase =
GCHandle.InternalGet(gchandle);
719 [DebuggerNonUserCode]
720 private void CtorCollectibleVirtualDispatch(
object target, IntPtr methodPtr, IntPtr shuffleThunk, IntPtr gchandle)
723 _methodPtr = shuffleThunk;
724 _methodPtrAux = GetCallStub(methodPtr);
725 _methodBase =
GCHandle.InternalGet(gchandle);
override MethodInfo GetMethodImpl()
Returns a static method represented by the current T:System.MulticastDelegate.
MulticastDelegate(Type target, string method)
Initializes a new instance of the T:System.MulticastDelegate class.
sealed override int GetHashCode()
Returns the hash code for this instance.
Discovers the attributes of a method and provides access to method metadata.
static bool operator==(MulticastDelegate d1, MulticastDelegate d2)
Determines whether two T:System.MulticastDelegate objects are equal.
Represents a multicast delegate; that is, a delegate that can have more than one element in its invoc...
object Target
Gets the class instance on which the current delegate invokes the instance method.
Represents a type using an internal metadata token.
static bool operator !=(MulticastDelegate d1, MulticastDelegate d2)
Determines whether two T:System.MulticastDelegate objects are not equal.
Describes the source and destination of a given serialized stream, and provides an additional caller-...
Provides information about, and means to manipulate, the current environment and platform....
T:System.RuntimeMethodHandle is a handle to the internal metadata representation of a method.
override void GetObjectData(SerializationInfo info, StreamingContext context)
Populates a T:System.Runtime.Serialization.SerializationInfo object with all the data needed to seria...
static int CompareExchange(ref int location1, int value, int comparand)
Compares two 32-bit signed integers for equality and, if they are equal, replaces the first value.
A platform-specific type that is used to represent a pointer or a handle.
Represents a delegate, which is a data structure that refers to a static method or to a class instanc...
Represents type declarations: class types, interface types, array types, value types,...
The exception thrown when an error occurs during serialization or deserialization.
Provides a way to access a managed object from unmanaged memory.
Stores all the data needed to serialize or deserialize an object. This class cannot be inherited.
MethodInfo Method
Gets the method represented by the delegate.
The exception that is thrown when one of the arguments provided to a method is not valid.
sealed override Delegate CombineImpl(Delegate follow)
Combines this T:System.Delegate with the specified T:System.Delegate to form a new delegate.
Specifies that the class can be serialized.
sealed override bool Equals(object obj)
Determines whether this multicast delegate and the specified object are equal.
sealed override Delegate RemoveImpl(Delegate value)
Removes an element from the invocation list of this T:System.MulticastDelegate that is equal to the s...
sealed override Delegate [] GetInvocationList()
Returns the invocation list of this multicast delegate, in invocation order.
Delegate(object target, string method)
Initializes a delegate that invokes the specified instance method on the specified class instance.
Provides atomic operations for variables that are shared by multiple threads.
Provides the base class for value types.
MulticastDelegate(object target, string method)
Initializes a new instance of the T:System.MulticastDelegate class.
Attribute can be applied to a delegate.