Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
MulticastDelegate.cs
Go to the documentation of this file.
10
11namespace System;
12
14[ComVisible(true)]
15public abstract class MulticastDelegate : Delegate
16{
17 private object _invocationList;
18
20
21 [RequiresUnreferencedCode("The target method might be removed")]
22 protected MulticastDelegate(object target, string method)
23 : base(target, method)
24 {
25 }
26
28 : base(target, method)
29 {
30 }
31
32 internal bool IsUnmanagedFunctionPtr()
33 {
34 return _invocationCount == (IntPtr)(-1);
35 }
36
38 {
40 {
42 }
43 return true;
44 }
45
50
51 public sealed override bool Equals([NotNullWhen(true)] object? obj)
52 {
53 if (obj == null)
54 {
55 return false;
56 }
57 if (this == obj)
58 {
59 return true;
60 }
62 {
63 return false;
64 }
66 if (_invocationCount != (IntPtr)0)
67 {
69 {
71 {
72 if (!multicastDelegate.IsUnmanagedFunctionPtr())
73 {
74 return false;
75 }
77 }
78 if (multicastDelegate._invocationList is Delegate)
79 {
80 return Equals(multicastDelegate._invocationList);
81 }
82 return base.Equals(obj);
83 }
85 {
86 return @delegate.Equals(obj);
87 }
89 }
91 {
92 if (!_invocationList.Equals(multicastDelegate._invocationList))
93 {
94 return false;
95 }
96 return base.Equals((object?)multicastDelegate);
97 }
98 if (multicastDelegate._invocationList is Delegate)
99 {
100 return Equals(multicastDelegate._invocationList);
101 }
102 return base.Equals((object?)multicastDelegate);
103 }
104
106 {
107 object[] array = (object[])_invocationList;
108 if (d._invocationCount != _invocationCount)
109 {
110 return false;
111 }
112 int num = (int)_invocationCount;
113 for (int i = 0; i < num; i++)
114 {
116 object[] array2 = d._invocationList as object[];
117 if (!@delegate.Equals(array2[i]))
118 {
119 return false;
120 }
121 }
122 return true;
123 }
124
125 private static bool TrySetSlot(object[] a, int index, object o)
126 {
127 if (a[index] == null && Interlocked.CompareExchange<object>(ref a[index], o, (object)null) == null)
128 {
129 return true;
130 }
131 object obj = a[index];
132 if (obj != null)
133 {
136 if (multicastDelegate2._methodPtr == multicastDelegate._methodPtr && multicastDelegate2._target == multicastDelegate._target && multicastDelegate2._methodPtrAux == multicastDelegate._methodPtrAux)
137 {
138 return true;
139 }
140 }
141 return false;
142 }
143
162
167
180
181 protected sealed override Delegate CombineImpl(Delegate? follow)
182 {
183 if ((object)follow == null)
184 {
185 return this;
186 }
188 {
190 }
192 int num = 1;
193 object[] array = multicastDelegate._invocationList as object[];
194 if (array != null)
195 {
196 num = (int)multicastDelegate._invocationCount;
197 }
198 int num2;
199 object[] array3;
200 if (!(_invocationList is object[] array2))
201 {
202 num2 = 1 + num;
203 array3 = new object[num2];
204 array3[0] = this;
205 if (array == null)
206 {
208 }
209 else
210 {
211 for (int i = 0; i < num; i++)
212 {
213 array3[1 + i] = array[i];
214 }
215 }
217 }
218 int num3 = (int)_invocationCount;
219 num2 = num3 + num;
220 array3 = null;
221 if (num2 <= array2.Length)
222 {
223 array3 = array2;
224 if (array == null)
225 {
227 {
228 array3 = null;
229 }
230 }
231 else
232 {
233 for (int j = 0; j < num; j++)
234 {
235 if (!TrySetSlot(array3, num3 + j, array[j]))
236 {
237 array3 = null;
238 break;
239 }
240 }
241 }
242 }
243 if (array3 == null)
244 {
245 int num4;
246 for (num4 = array2.Length; num4 < num2; num4 *= 2)
247 {
248 }
249 array3 = new object[num4];
250 for (int k = 0; k < num3; k++)
251 {
252 array3[k] = array2[k];
253 }
254 if (array == null)
255 {
257 }
258 else
259 {
260 for (int l = 0; l < num; l++)
261 {
262 array3[num3 + l] = array[l];
263 }
264 }
265 }
267 }
268
270 {
271 object[] array = (object[])_invocationList;
272 int num = array.Length;
273 while (num / 2 >= invocationCount - deleteCount)
274 {
275 num /= 2;
276 }
277 object[] array2 = new object[num];
278 for (int i = 0; i < deleteIndex; i++)
279 {
280 array2[i] = invocationList[i];
281 }
282 for (int j = deleteIndex + deleteCount; j < invocationCount; j++)
283 {
285 }
286 return array2;
287 }
288
289 private static bool EqualInvocationLists(object[] a, object[] b, int start, int count)
290 {
291 for (int i = 0; i < count; i++)
292 {
293 if (!a[start + i].Equals(b[i]))
294 {
295 return false;
296 }
297 }
298 return true;
299 }
300
301 protected sealed override Delegate? RemoveImpl(Delegate value)
302 {
304 {
305 return this;
306 }
307 if (!(multicastDelegate._invocationList is object[]))
308 {
309 if (!(_invocationList is object[] array))
310 {
311 if (Equals(value))
312 {
313 return null;
314 }
315 }
316 else
317 {
318 int num = (int)_invocationCount;
319 int num2 = num;
320 while (--num2 >= 0)
321 {
322 if (value.Equals(array[num2]))
323 {
324 if (num == 2)
325 {
326 return (Delegate)array[1 - num2];
327 }
330 }
331 }
332 }
333 }
334 else if (_invocationList is object[] array2)
335 {
336 int num3 = (int)_invocationCount;
337 int num4 = (int)multicastDelegate._invocationCount;
338 for (int num5 = num3 - num4; num5 >= 0; num5--)
339 {
340 if (EqualInvocationLists(array2, multicastDelegate._invocationList as object[], num5, num4))
341 {
342 if (num3 - num4 == 0)
343 {
344 return null;
345 }
346 if (num3 - num4 == 1)
347 {
348 return (Delegate)array2[(num5 == 0) ? (num3 - 1) : 0];
349 }
352 }
353 }
354 }
355 return this;
356 }
357
358 public sealed override Delegate[] GetInvocationList()
359 {
361 if (!(_invocationList is object[] array))
362 {
363 array2 = new Delegate[1] { this };
364 }
365 else
366 {
367 array2 = new Delegate[(int)_invocationCount];
368 for (int i = 0; i < array2.Length; i++)
369 {
370 array2[i] = (Delegate)array[i];
371 }
372 }
373 return array2;
374 }
375
376 [MethodImpl(MethodImplOptions.AggressiveInlining)]
378 {
379 if ((object)d2 == null)
380 {
381 if ((object)d1 != null)
382 {
383 return false;
384 }
385 return true;
386 }
387 if ((object)d2 != d1)
388 {
389 return d2.Equals(d1);
390 }
391 return true;
392 }
393
394 [MethodImpl(MethodImplOptions.AggressiveInlining)]
396 {
397 if ((object)d2 == null)
398 {
399 if ((object)d1 != null)
400 {
401 return true;
402 }
403 return false;
404 }
405 if ((object)d2 != d1)
406 {
407 return !d2.Equals(d1);
408 }
409 return false;
410 }
411
412 public sealed override int GetHashCode()
413 {
415 {
417 }
419 {
420 return @delegate.GetHashCode();
421 }
422 if (!(_invocationList is object[] array))
423 {
424 return base.GetHashCode();
425 }
426 int num = 0;
427 for (int i = 0; i < (int)_invocationCount; i++)
428 {
429 num = num * 33 + array[i].GetHashCode();
430 }
431 return num;
432 }
433
434 internal override object GetTarget()
435 {
436 if (_invocationCount != (IntPtr)0)
437 {
439 {
440 return null;
441 }
442 if (_invocationList is object[] array)
443 {
444 int num = (int)_invocationCount;
445 return ((Delegate)array[num - 1]).GetTarget();
446 }
448 {
449 return @delegate.GetTarget();
450 }
451 }
452 return base.GetTarget();
453 }
454
455 protected override MethodInfo GetMethodImpl()
456 {
457 if (_invocationCount != (IntPtr)0 && _invocationList != null)
458 {
459 if (_invocationList is object[] array)
460 {
461 int num = (int)_invocationCount - 1;
462 return ((Delegate)array[num]).Method;
463 }
465 {
466 return multicastDelegate.GetMethodImpl();
467 }
468 }
469 else if (IsUnmanagedFunctionPtr())
470 {
471 if (_methodBase == null || !(_methodBase is MethodInfo))
472 {
476 {
479 }
481 }
482 return (MethodInfo)_methodBase;
483 }
484 return base.GetMethodImpl();
485 }
486
490 {
492 }
493
495 private void CtorClosed(object target, IntPtr methodPtr)
496 {
497 if (target == null)
498 {
500 }
501 _target = target;
503 }
504
506 private void CtorClosedStatic(object target, IntPtr methodPtr)
507 {
508 _target = target;
510 }
511
513 private void CtorRTClosed(object target, IntPtr methodPtr)
514 {
515 _target = target;
517 }
518
520 private void CtorOpened(object target, IntPtr methodPtr, IntPtr shuffleThunk)
521 {
522 _target = this;
525 }
526
529 {
530 _target = this;
533 }
534
537 {
538 _target = target;
541 }
542
551
560}
IntPtr _methodPtr
Definition Delegate.cs:17
object _target
Definition Delegate.cs:13
IRuntimeMethodInfo FindMethodHandle()
IntPtr _methodPtrAux
Definition Delegate.cs:19
IntPtr GetInvokeMethod()
IntPtr AdjustTarget(object target, IntPtr methodPtr)
static MulticastDelegate InternalAllocLike(Delegate d)
IntPtr GetCallStub(IntPtr methodPtr)
object _methodBase
Definition Delegate.cs:15
MethodInfo Method
Definition Delegate.cs:23
static bool InternalEqualTypes(object a, object b)
static bool CompareUnmanagedFunctionPtrs(Delegate d1, Delegate d2)
IntPtr GetMulticastInvoke()
void CtorCollectibleOpened(object target, IntPtr methodPtr, IntPtr shuffleThunk, IntPtr gchandle)
void CtorRTClosed(object target, IntPtr methodPtr)
static bool operator==(MulticastDelegate? d1, MulticastDelegate? d2)
static bool TrySetSlot(object[] a, int index, object o)
static bool operator!=(MulticastDelegate? d1, MulticastDelegate? d2)
void CtorOpened(object target, IntPtr methodPtr, IntPtr shuffleThunk)
MulticastDelegate NewMulticastDelegate(object[] invocationList, int invocationCount, bool thisIsMultiCastAlready)
override? Delegate RemoveImpl(Delegate value)
void CtorClosed(object target, IntPtr methodPtr)
MulticastDelegate([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type target, string method)
static void ThrowNullThisInDelegateToInstance()
void CtorCollectibleClosedStatic(object target, IntPtr methodPtr, IntPtr gchandle)
MulticastDelegate(object target, string method)
override bool Equals([NotNullWhen(true)] object? obj)
override Delegate[] GetInvocationList()
void CtorCollectibleVirtualDispatch(object target, IntPtr methodPtr, IntPtr shuffleThunk, IntPtr gchandle)
bool InvocationListEquals(MulticastDelegate d)
object[] DeleteFromInvocationList(object[] invocationList, int invocationCount, int deleteIndex, int deleteCount)
override MethodInfo GetMethodImpl()
MulticastDelegate NewMulticastDelegate(object[] invocationList, int invocationCount)
override void GetObjectData(SerializationInfo info, StreamingContext context)
override Delegate CombineImpl(Delegate? follow)
void StoreDynamicMethod(MethodInfo dynamicMethod)
static bool EqualInvocationLists(object[] a, object[] b, int start, int count)
void CtorClosedStatic(object target, IntPtr methodPtr)
void CtorVirtualDispatch(object target, IntPtr methodPtr, IntPtr shuffleThunk)
static MethodBase GetMethodBase(RuntimeModule scope, int typeMetadataToken)
static string Arg_DlgtNullInst
Definition SR.cs:120
static string Arg_DlgtTypeMis
Definition SR.cs:124
static string Serialization_DelegatesNotSupported
Definition SR.cs:1876
Definition SR.cs:7
static int CompareExchange(ref int location1, int value, int comparand)
static int GetHashCodeOfPtr(IntPtr ptr)
static RuntimeType GetDeclaringType(RuntimeMethodHandleInternal method)
static bool HasInstantiation(RuntimeType type)
static bool IsGenericTypeDefinition(RuntimeType type)
static unsafe object InternalGet(IntPtr handle)
Definition GCHandle.cs:40