Terraria v1.4.4.9
Terraria source code documentation
All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events Macros
DefaultBinder.cs
Go to the documentation of this file.
3
4namespace System;
5
6internal class DefaultBinder : Binder
7{
8 [Flags]
9 private enum Primitives
10 {
11 Boolean = 8,
12 Char = 0x10,
13 SByte = 0x20,
14 Byte = 0x40,
15 Int16 = 0x80,
16 UInt16 = 0x100,
17 Int32 = 0x200,
18 UInt32 = 0x400,
19 Int64 = 0x800,
20 UInt64 = 0x1000,
21 Single = 0x2000,
22 Double = 0x4000,
23 Decimal = 0x8000,
24 DateTime = 0x10000,
25 String = 0x40000
26 }
27
28 internal sealed class BinderState
29 {
30 internal readonly int[] _argsMap;
31
32 internal readonly int _originalSize;
33
34 internal readonly bool _isParamArray;
35
36 internal BinderState(int[] argsMap, int originalSize, bool isParamArray)
37 {
38 _argsMap = argsMap;
39 _originalSize = originalSize;
40 _isParamArray = isParamArray;
41 }
42 }
43
44 private static readonly Primitives[] s_primitiveConversions = new Primitives[19]
45 {
46 (Primitives)0,
47 (Primitives)0,
48 (Primitives)0,
49 Primitives.Boolean,
50 Primitives.Char | Primitives.UInt16 | Primitives.Int32 | Primitives.UInt32 | Primitives.Int64 | Primitives.UInt64 | Primitives.Single | Primitives.Double,
51 Primitives.SByte | Primitives.Int16 | Primitives.Int32 | Primitives.Int64 | Primitives.Single | Primitives.Double,
52 Primitives.Char | Primitives.Byte | Primitives.Int16 | Primitives.UInt16 | Primitives.Int32 | Primitives.UInt32 | Primitives.Int64 | Primitives.UInt64 | Primitives.Single | Primitives.Double,
53 Primitives.Int16 | Primitives.Int32 | Primitives.Int64 | Primitives.Single | Primitives.Double,
54 Primitives.UInt16 | Primitives.Int32 | Primitives.UInt32 | Primitives.Int64 | Primitives.UInt64 | Primitives.Single | Primitives.Double,
55 Primitives.Int32 | Primitives.Int64 | Primitives.Single | Primitives.Double,
56 Primitives.UInt32 | Primitives.Int64 | Primitives.UInt64 | Primitives.Single | Primitives.Double,
57 Primitives.Int64 | Primitives.Single | Primitives.Double,
58 Primitives.UInt64 | Primitives.Single | Primitives.Double,
59 Primitives.Single | Primitives.Double,
60 Primitives.Double,
61 Primitives.Decimal,
62 Primitives.DateTime,
63 (Primitives)0,
64 Primitives.String
65 };
66
67 public sealed override MethodBase BindToMethod(BindingFlags bindingAttr, MethodBase[] match, ref object[] args, ParameterModifier[] modifiers, CultureInfo cultureInfo, string[] names, out object state)
68 {
69 if (match == null || match.Length == 0)
70 {
71 throw new ArgumentException(SR.Arg_EmptyArray, "match");
72 }
73 MethodBase[] array = (MethodBase[])match.Clone();
74 state = null;
75 int[][] array2 = new int[array.Length][];
76 for (int i = 0; i < array.Length; i++)
77 {
78 ParameterInfo[] parametersNoCopy = array[i].GetParametersNoCopy();
79 array2[i] = new int[(parametersNoCopy.Length > args.Length) ? parametersNoCopy.Length : args.Length];
80 if (names == null)
81 {
82 for (int j = 0; j < args.Length; j++)
83 {
84 array2[i][j] = j;
85 }
86 }
87 else if (!CreateParamOrder(array2[i], parametersNoCopy, names))
88 {
89 array[i] = null;
90 }
91 }
92 Type[] array3 = new Type[array.Length];
93 Type[] array4 = new Type[args.Length];
94 for (int i = 0; i < args.Length; i++)
95 {
96 if (args[i] != null)
97 {
98 array4[i] = args[i].GetType();
99 }
100 }
101 int num = 0;
102 bool flag = (bindingAttr & BindingFlags.OptionalParamBinding) != 0;
103 for (int i = 0; i < array.Length; i++)
104 {
105 Type type = null;
106 if (array[i] == null)
107 {
108 continue;
109 }
110 ParameterInfo[] parametersNoCopy2 = array[i].GetParametersNoCopy();
111 if (parametersNoCopy2.Length == 0)
112 {
113 if (args.Length == 0 || (array[i].CallingConvention & CallingConventions.VarArgs) != 0)
114 {
115 array2[num] = array2[i];
116 array[num++] = array[i];
117 }
118 continue;
119 }
120 int j;
121 if (parametersNoCopy2.Length > args.Length)
122 {
123 for (j = args.Length; j < parametersNoCopy2.Length - 1 && parametersNoCopy2[j].DefaultValue != DBNull.Value; j++)
124 {
125 }
126 if (j != parametersNoCopy2.Length - 1)
127 {
128 continue;
129 }
130 if (parametersNoCopy2[j].DefaultValue == DBNull.Value)
131 {
132 if (!parametersNoCopy2[j].ParameterType.IsArray || !parametersNoCopy2[j].IsDefined(typeof(ParamArrayAttribute), inherit: true))
133 {
134 continue;
135 }
136 type = parametersNoCopy2[j].ParameterType.GetElementType();
137 }
138 }
139 else if (parametersNoCopy2.Length < args.Length)
140 {
141 int num2 = parametersNoCopy2.Length - 1;
142 if (!parametersNoCopy2[num2].ParameterType.IsArray || !parametersNoCopy2[num2].IsDefined(typeof(ParamArrayAttribute), inherit: true) || array2[i][num2] != num2)
143 {
144 continue;
145 }
146 type = parametersNoCopy2[num2].ParameterType.GetElementType();
147 }
148 else
149 {
150 int num3 = parametersNoCopy2.Length - 1;
151 if (parametersNoCopy2[num3].ParameterType.IsArray && parametersNoCopy2[num3].IsDefined(typeof(ParamArrayAttribute), inherit: true) && array2[i][num3] == num3 && !parametersNoCopy2[num3].ParameterType.IsAssignableFrom(array4[num3]))
152 {
153 type = parametersNoCopy2[num3].ParameterType.GetElementType();
154 }
155 }
156 int num4 = ((type != null) ? (parametersNoCopy2.Length - 1) : args.Length);
157 for (j = 0; j < num4; j++)
158 {
159 Type type2 = parametersNoCopy2[j].ParameterType;
160 if (type2.IsByRef)
161 {
162 type2 = type2.GetElementType();
163 }
164 if (type2 == array4[array2[i][j]] || (flag && args[array2[i][j]] == Type.Missing) || args[array2[i][j]] == null || type2 == typeof(object))
165 {
166 continue;
167 }
168 if (type2.IsPrimitive)
169 {
170 if (array4[array2[i][j]] == null || !CanChangePrimitive(args[array2[i][j]]?.GetType(), type2))
171 {
172 break;
173 }
174 }
175 else if (!(array4[array2[i][j]] == null) && !type2.IsAssignableFrom(array4[array2[i][j]]) && (!array4[array2[i][j]].IsCOMObject || !type2.IsInstanceOfType(args[array2[i][j]])))
176 {
177 break;
178 }
179 }
180 if (type != null && j == parametersNoCopy2.Length - 1)
181 {
182 for (; j < args.Length; j++)
183 {
184 if (type.IsPrimitive)
185 {
186 if (array4[j] == null || !CanChangePrimitive(args[j]?.GetType(), type))
187 {
188 break;
189 }
190 }
191 else if (!(array4[j] == null) && !type.IsAssignableFrom(array4[j]) && (!array4[j].IsCOMObject || !type.IsInstanceOfType(args[j])))
192 {
193 break;
194 }
195 }
196 }
197 if (j == args.Length)
198 {
199 array2[num] = array2[i];
200 array3[num] = type;
201 array[num++] = array[i];
202 }
203 }
204 switch (num)
205 {
206 case 0:
208 case 1:
209 {
210 if (names != null)
211 {
212 state = new BinderState((int[])array2[0].Clone(), args.Length, array3[0] != null);
213 ReorderParams(array2[0], args);
214 }
215 ParameterInfo[] parametersNoCopy4 = array[0].GetParametersNoCopy();
216 if (parametersNoCopy4.Length == args.Length)
217 {
218 if (array3[0] != null)
219 {
220 object[] array8 = new object[parametersNoCopy4.Length];
221 int num8 = parametersNoCopy4.Length - 1;
222 Array.Copy(args, array8, num8);
223 array8[num8] = Array.CreateInstance(array3[0], 1);
224 ((Array)array8[num8]).SetValue(args[num8], 0);
225 args = array8;
226 }
227 }
228 else if (parametersNoCopy4.Length > args.Length)
229 {
230 object[] array9 = new object[parametersNoCopy4.Length];
231 int i;
232 for (i = 0; i < args.Length; i++)
233 {
234 array9[i] = args[i];
235 }
236 for (; i < parametersNoCopy4.Length - 1; i++)
237 {
238 array9[i] = parametersNoCopy4[i].DefaultValue;
239 }
240 if (array3[0] != null)
241 {
242 array9[i] = Array.CreateInstance(array3[0], 0);
243 }
244 else
245 {
246 array9[i] = parametersNoCopy4[i].DefaultValue;
247 }
248 args = array9;
249 }
250 else if ((array[0].CallingConvention & CallingConventions.VarArgs) == 0)
251 {
252 object[] array10 = new object[parametersNoCopy4.Length];
253 int num9 = parametersNoCopy4.Length - 1;
254 Array.Copy(args, array10, num9);
255 array10[num9] = Array.CreateInstance(array3[0], args.Length - num9);
256 Array.Copy(args, num9, (Array)array10[num9], 0, args.Length - num9);
257 args = array10;
258 }
259 return array[0];
260 }
261 default:
262 {
263 int num5 = 0;
264 bool flag2 = false;
265 for (int i = 1; i < num; i++)
266 {
267 switch (FindMostSpecificMethod(array[num5], array2[num5], array3[num5], array[i], array2[i], array3[i], array4, args))
268 {
269 case 0:
270 flag2 = true;
271 break;
272 case 2:
273 num5 = i;
274 flag2 = false;
275 break;
276 }
277 }
278 if (flag2)
279 {
281 }
282 if (names != null)
283 {
284 state = new BinderState((int[])array2[num5].Clone(), args.Length, array3[num5] != null);
285 ReorderParams(array2[num5], args);
286 }
287 ParameterInfo[] parametersNoCopy3 = array[num5].GetParametersNoCopy();
288 if (parametersNoCopy3.Length == args.Length)
289 {
290 if (array3[num5] != null)
291 {
292 object[] array5 = new object[parametersNoCopy3.Length];
293 int num6 = parametersNoCopy3.Length - 1;
294 Array.Copy(args, array5, num6);
295 array5[num6] = Array.CreateInstance(array3[num5], 1);
296 ((Array)array5[num6]).SetValue(args[num6], 0);
297 args = array5;
298 }
299 }
300 else if (parametersNoCopy3.Length > args.Length)
301 {
302 object[] array6 = new object[parametersNoCopy3.Length];
303 int i;
304 for (i = 0; i < args.Length; i++)
305 {
306 array6[i] = args[i];
307 }
308 for (; i < parametersNoCopy3.Length - 1; i++)
309 {
310 array6[i] = parametersNoCopy3[i].DefaultValue;
311 }
312 if (array3[num5] != null)
313 {
314 array6[i] = Array.CreateInstance(array3[num5], 0);
315 }
316 else
317 {
318 array6[i] = parametersNoCopy3[i].DefaultValue;
319 }
320 args = array6;
321 }
322 else if ((array[num5].CallingConvention & CallingConventions.VarArgs) == 0)
323 {
324 object[] array7 = new object[parametersNoCopy3.Length];
325 int num7 = parametersNoCopy3.Length - 1;
326 Array.Copy(args, array7, num7);
327 array7[num7] = Array.CreateInstance(array3[num5], args.Length - num7);
328 Array.Copy(args, num7, (Array)array7[num7], 0, args.Length - num7);
329 args = array7;
330 }
331 return array[num5];
332 }
333 }
334 }
335
336 public sealed override FieldInfo BindToField(BindingFlags bindingAttr, FieldInfo[] match, object value, CultureInfo cultureInfo)
337 {
338 if (match == null)
339 {
340 throw new ArgumentNullException("match");
341 }
342 int num = 0;
343 FieldInfo[] array = (FieldInfo[])match.Clone();
344 if ((bindingAttr & BindingFlags.SetField) != 0)
345 {
347 for (int i = 0; i < array.Length; i++)
348 {
349 Type fieldType = array[i].FieldType;
350 if (fieldType == type)
351 {
352 array[num++] = array[i];
353 }
354 else if (value == Empty.Value && fieldType.IsClass)
355 {
356 array[num++] = array[i];
357 }
358 else if (fieldType == typeof(object))
359 {
360 array[num++] = array[i];
361 }
362 else if (fieldType.IsPrimitive)
363 {
364 if (CanChangePrimitive(type, fieldType))
365 {
366 array[num++] = array[i];
367 }
368 }
369 else if (fieldType.IsAssignableFrom(type))
370 {
371 array[num++] = array[i];
372 }
373 }
374 switch (num)
375 {
376 case 0:
378 case 1:
379 return array[0];
380 }
381 }
382 int num2 = 0;
383 bool flag = false;
384 for (int i = 1; i < num; i++)
385 {
386 switch (FindMostSpecificField(array[num2], array[i]))
387 {
388 case 0:
389 flag = true;
390 break;
391 case 2:
392 num2 = i;
393 flag = false;
394 break;
395 }
396 }
397 if (flag)
398 {
400 }
401 return array[num2];
402 }
403
404 public sealed override MethodBase SelectMethod(BindingFlags bindingAttr, MethodBase[] match, Type[] types, ParameterModifier[] modifiers)
405 {
406 Type[] array = new Type[types.Length];
407 for (int i = 0; i < types.Length; i++)
408 {
409 array[i] = types[i].UnderlyingSystemType;
410 if (!array[i].IsRuntimeImplemented() && !(array[i] is SignatureType))
411 {
412 throw new ArgumentException(SR.Arg_MustBeType, "types");
413 }
414 }
415 types = array;
416 if (match == null || match.Length == 0)
417 {
418 throw new ArgumentException(SR.Arg_EmptyArray, "match");
419 }
420 MethodBase[] array2 = (MethodBase[])match.Clone();
421 int num = 0;
422 for (int i = 0; i < array2.Length; i++)
423 {
424 ParameterInfo[] parametersNoCopy = array2[i].GetParametersNoCopy();
425 if (parametersNoCopy.Length != types.Length)
426 {
427 continue;
428 }
429 int j;
430 for (j = 0; j < types.Length; j++)
431 {
432 Type parameterType = parametersNoCopy[j].ParameterType;
433 if (types[j].MatchesParameterTypeExactly(parametersNoCopy[j]) || parameterType == typeof(object))
434 {
435 continue;
436 }
437 Type type = types[j];
438 if (type is SignatureType signatureType)
439 {
440 if (!(array2[i] is MethodInfo genericMethod))
441 {
442 break;
443 }
444 type = signatureType.TryResolveAgainstGenericMethod(genericMethod);
445 if (type == null)
446 {
447 break;
448 }
449 }
450 if (parameterType.IsPrimitive)
451 {
452 if (!type.UnderlyingSystemType.IsRuntimeImplemented() || !CanChangePrimitive(type.UnderlyingSystemType, parameterType.UnderlyingSystemType))
453 {
454 break;
455 }
456 }
457 else if (!parameterType.IsAssignableFrom(type))
458 {
459 break;
460 }
461 }
462 if (j == types.Length)
463 {
464 array2[num++] = array2[i];
465 }
466 }
467 switch (num)
468 {
469 case 0:
470 return null;
471 case 1:
472 return array2[0];
473 default:
474 {
475 int num2 = 0;
476 bool flag = false;
477 int[] array3 = new int[types.Length];
478 for (int i = 0; i < types.Length; i++)
479 {
480 array3[i] = i;
481 }
482 for (int i = 1; i < num; i++)
483 {
484 switch (FindMostSpecificMethod(array2[num2], array3, null, array2[i], array3, null, types, null))
485 {
486 case 0:
487 flag = true;
488 break;
489 case 2:
490 flag = false;
491 num2 = i;
492 break;
493 }
494 }
495 if (flag)
496 {
498 }
499 return array2[num2];
500 }
501 }
502 }
503
504 public sealed override PropertyInfo SelectProperty(BindingFlags bindingAttr, PropertyInfo[] match, Type returnType, Type[] indexes, ParameterModifier[] modifiers)
505 {
506 if (indexes != null)
507 {
508 foreach (Type type in indexes)
509 {
510 if (type == null)
511 {
512 throw new ArgumentNullException("indexes");
513 }
514 }
515 }
516 if (match == null || match.Length == 0)
517 {
518 throw new ArgumentException(SR.Arg_EmptyArray, "match");
519 }
520 PropertyInfo[] array = (PropertyInfo[])match.Clone();
521 int j = 0;
522 int num = 0;
523 int num2 = ((indexes != null) ? indexes.Length : 0);
524 for (int k = 0; k < array.Length; k++)
525 {
526 if (indexes != null)
527 {
528 ParameterInfo[] indexParameters = array[k].GetIndexParameters();
529 if (indexParameters.Length != num2)
530 {
531 continue;
532 }
533 for (j = 0; j < num2; j++)
534 {
535 Type parameterType = indexParameters[j].ParameterType;
536 if (parameterType == indexes[j] || parameterType == typeof(object))
537 {
538 continue;
539 }
540 if (parameterType.IsPrimitive)
541 {
542 if (!indexes[j].UnderlyingSystemType.IsRuntimeImplemented() || !CanChangePrimitive(indexes[j].UnderlyingSystemType, parameterType.UnderlyingSystemType))
543 {
544 break;
545 }
546 }
547 else if (!parameterType.IsAssignableFrom(indexes[j]))
548 {
549 break;
550 }
551 }
552 }
553 if (j != num2)
554 {
555 continue;
556 }
557 if (returnType != null)
558 {
559 if (array[k].PropertyType.IsPrimitive)
560 {
562 {
563 continue;
564 }
565 }
566 else if (!array[k].PropertyType.IsAssignableFrom(returnType))
567 {
568 continue;
569 }
570 }
571 array[num++] = array[k];
572 }
573 switch (num)
574 {
575 case 0:
576 return null;
577 case 1:
578 return array[0];
579 default:
580 {
581 int num3 = 0;
582 bool flag = false;
583 int[] array2 = new int[num2];
584 for (int k = 0; k < num2; k++)
585 {
586 array2[k] = k;
587 }
588 for (int k = 1; k < num; k++)
589 {
590 int num4 = FindMostSpecificType(array[num3].PropertyType, array[k].PropertyType, returnType);
591 if (num4 == 0 && indexes != null)
592 {
593 num4 = FindMostSpecific(array[num3].GetIndexParameters(), array2, null, array[k].GetIndexParameters(), array2, null, indexes, null);
594 }
595 if (num4 == 0)
596 {
597 num4 = FindMostSpecificProperty(array[num3], array[k]);
598 if (num4 == 0)
599 {
600 flag = true;
601 }
602 }
603 if (num4 == 2)
604 {
605 flag = false;
606 num3 = k;
607 }
608 }
609 if (flag)
610 {
612 }
613 return array[num3];
614 }
615 }
616 }
617
618 public override object ChangeType(object value, Type type, CultureInfo cultureInfo)
619 {
621 }
622
623 public sealed override void ReorderArgumentArray(ref object[] args, object state)
624 {
625 BinderState binderState = (BinderState)state;
626 ReorderParams(binderState._argsMap, args);
627 if (binderState._isParamArray)
628 {
629 int num = args.Length - 1;
630 if (args.Length == binderState._originalSize)
631 {
632 args[num] = ((object[])args[num])[0];
633 return;
634 }
635 object[] array = new object[args.Length];
636 Array.Copy(args, array, num);
637 int num2 = num;
638 int num3 = 0;
639 while (num2 < array.Length)
640 {
641 array[num2] = ((object[])args[num])[num3];
642 num2++;
643 num3++;
644 }
645 args = array;
646 }
647 else if (args.Length > binderState._originalSize)
648 {
649 object[] array2 = new object[binderState._originalSize];
650 Array.Copy(args, array2, binderState._originalSize);
651 args = array2;
652 }
653 }
654
655 public static MethodBase ExactBinding(MethodBase[] match, Type[] types, ParameterModifier[] modifiers)
656 {
657 if (match == null)
658 {
659 throw new ArgumentNullException("match");
660 }
661 MethodBase[] array = new MethodBase[match.Length];
662 int num = 0;
663 for (int i = 0; i < match.Length; i++)
664 {
665 ParameterInfo[] parametersNoCopy = match[i].GetParametersNoCopy();
666 if (parametersNoCopy.Length == 0)
667 {
668 continue;
669 }
670 int j;
671 for (j = 0; j < types.Length; j++)
672 {
673 Type parameterType = parametersNoCopy[j].ParameterType;
674 if (!parameterType.Equals(types[j]))
675 {
676 break;
677 }
678 }
679 if (j >= types.Length)
680 {
681 array[num] = match[i];
682 num++;
683 }
684 }
685 return num switch
686 {
687 0 => null,
688 1 => array[0],
690 };
691 }
692
693 public static PropertyInfo ExactPropertyBinding(PropertyInfo[] match, Type returnType, Type[] types, ParameterModifier[] modifiers)
694 {
695 if (match == null)
696 {
697 throw new ArgumentNullException("match");
698 }
699 PropertyInfo propertyInfo = null;
700 int num = ((types != null) ? types.Length : 0);
701 for (int i = 0; i < match.Length; i++)
702 {
703 ParameterInfo[] indexParameters = match[i].GetIndexParameters();
704 int j;
705 for (j = 0; j < num; j++)
706 {
707 Type parameterType = indexParameters[j].ParameterType;
708 if (parameterType != types[j])
709 {
710 break;
711 }
712 }
713 if (j >= num && (!(returnType != null) || !(returnType != match[i].PropertyType)))
714 {
715 if (propertyInfo != null)
716 {
718 }
719 propertyInfo = match[i];
720 }
721 }
722 return propertyInfo;
723 }
724
725 private static int FindMostSpecific(ParameterInfo[] p1, int[] paramOrder1, Type paramArrayType1, ParameterInfo[] p2, int[] paramOrder2, Type paramArrayType2, Type[] types, object[] args)
726 {
727 if (paramArrayType1 != null && paramArrayType2 == null)
728 {
729 return 2;
730 }
731 if (paramArrayType2 != null && paramArrayType1 == null)
732 {
733 return 1;
734 }
735 bool flag = false;
736 bool flag2 = false;
737 for (int i = 0; i < types.Length; i++)
738 {
739 if (args != null && args[i] == Type.Missing)
740 {
741 continue;
742 }
743 Type type = ((!(paramArrayType1 != null) || paramOrder1[i] < p1.Length - 1) ? p1[paramOrder1[i]].ParameterType : paramArrayType1);
744 Type type2 = ((!(paramArrayType2 != null) || paramOrder2[i] < p2.Length - 1) ? p2[paramOrder2[i]].ParameterType : paramArrayType2);
745 if (!(type == type2))
746 {
747 switch (FindMostSpecificType(type, type2, types[i]))
748 {
749 case 0:
750 return 0;
751 case 1:
752 flag = true;
753 break;
754 case 2:
755 flag2 = true;
756 break;
757 }
758 }
759 }
760 if (flag == flag2)
761 {
762 if (!flag && args != null)
763 {
764 if (p1.Length > p2.Length)
765 {
766 return 1;
767 }
768 if (p2.Length > p1.Length)
769 {
770 return 2;
771 }
772 }
773 return 0;
774 }
775 if (!flag)
776 {
777 return 2;
778 }
779 return 1;
780 }
781
782 private static int FindMostSpecificType(Type c1, Type c2, Type t)
783 {
784 if (c1 == c2)
785 {
786 return 0;
787 }
788 if (t is SignatureType pattern)
789 {
790 if (pattern.MatchesExactly(c1))
791 {
792 return 1;
793 }
794 if (pattern.MatchesExactly(c2))
795 {
796 return 2;
797 }
798 }
799 else
800 {
801 if (c1 == t)
802 {
803 return 1;
804 }
805 if (c2 == t)
806 {
807 return 2;
808 }
809 }
810 if (c1.IsByRef || c2.IsByRef)
811 {
812 if (c1.IsByRef && c2.IsByRef)
813 {
814 c1 = c1.GetElementType();
815 c2 = c2.GetElementType();
816 }
817 else if (c1.IsByRef)
818 {
819 if (c1.GetElementType() == c2)
820 {
821 return 2;
822 }
823 c1 = c1.GetElementType();
824 }
825 else
826 {
827 if (c2.GetElementType() == c1)
828 {
829 return 1;
830 }
831 c2 = c2.GetElementType();
832 }
833 }
834 bool flag;
835 bool flag2;
836 if (c1.IsPrimitive && c2.IsPrimitive)
837 {
838 flag = CanChangePrimitive(c2, c1);
839 flag2 = CanChangePrimitive(c1, c2);
840 }
841 else
842 {
843 flag = c1.IsAssignableFrom(c2);
844 flag2 = c2.IsAssignableFrom(c1);
845 }
846 if (flag == flag2)
847 {
848 return 0;
849 }
850 if (flag)
851 {
852 return 2;
853 }
854 return 1;
855 }
856
857 private static int FindMostSpecificMethod(MethodBase m1, int[] paramOrder1, Type paramArrayType1, MethodBase m2, int[] paramOrder2, Type paramArrayType2, Type[] types, object[] args)
858 {
859 int num = FindMostSpecific(m1.GetParametersNoCopy(), paramOrder1, paramArrayType1, m2.GetParametersNoCopy(), paramOrder2, paramArrayType2, types, args);
860 if (num != 0)
861 {
862 return num;
863 }
864 if (CompareMethodSig(m1, m2))
865 {
866 int hierarchyDepth = GetHierarchyDepth(m1.DeclaringType);
867 int hierarchyDepth2 = GetHierarchyDepth(m2.DeclaringType);
868 if (hierarchyDepth == hierarchyDepth2)
869 {
870 return 0;
871 }
872 if (hierarchyDepth < hierarchyDepth2)
873 {
874 return 2;
875 }
876 return 1;
877 }
878 return 0;
879 }
880
881 private static int FindMostSpecificField(FieldInfo cur1, FieldInfo cur2)
882 {
883 if (cur1.Name == cur2.Name)
884 {
885 int hierarchyDepth = GetHierarchyDepth(cur1.DeclaringType);
886 int hierarchyDepth2 = GetHierarchyDepth(cur2.DeclaringType);
887 if (hierarchyDepth == hierarchyDepth2)
888 {
889 return 0;
890 }
891 if (hierarchyDepth < hierarchyDepth2)
892 {
893 return 2;
894 }
895 return 1;
896 }
897 return 0;
898 }
899
901 {
902 if (cur1.Name == cur2.Name)
903 {
904 int hierarchyDepth = GetHierarchyDepth(cur1.DeclaringType);
905 int hierarchyDepth2 = GetHierarchyDepth(cur2.DeclaringType);
906 if (hierarchyDepth == hierarchyDepth2)
907 {
908 return 0;
909 }
910 if (hierarchyDepth < hierarchyDepth2)
911 {
912 return 2;
913 }
914 return 1;
915 }
916 return 0;
917 }
918
919 public static bool CompareMethodSig(MethodBase m1, MethodBase m2)
920 {
921 ParameterInfo[] parametersNoCopy = m1.GetParametersNoCopy();
922 ParameterInfo[] parametersNoCopy2 = m2.GetParametersNoCopy();
923 if (parametersNoCopy.Length != parametersNoCopy2.Length)
924 {
925 return false;
926 }
927 int num = parametersNoCopy.Length;
928 for (int i = 0; i < num; i++)
929 {
930 if (parametersNoCopy[i].ParameterType != parametersNoCopy2[i].ParameterType)
931 {
932 return false;
933 }
934 }
935 return true;
936 }
937
938 private static int GetHierarchyDepth(Type t)
939 {
940 int num = 0;
941 Type type = t;
942 do
943 {
944 num++;
945 type = type.BaseType;
946 }
947 while (type != null);
948 return num;
949 }
950
951 internal static MethodBase FindMostDerivedNewSlotMeth(MethodBase[] match, int cMatches)
952 {
953 int num = 0;
954 MethodBase result = null;
955 for (int i = 0; i < cMatches; i++)
956 {
957 int hierarchyDepth = GetHierarchyDepth(match[i].DeclaringType);
958 if (hierarchyDepth == num)
959 {
961 }
962 if (hierarchyDepth > num)
963 {
964 num = hierarchyDepth;
965 result = match[i];
966 }
967 }
968 return result;
969 }
970
971 private static void ReorderParams(int[] paramOrder, object[] vars)
972 {
973 object[] array = new object[vars.Length];
974 for (int i = 0; i < vars.Length; i++)
975 {
976 array[i] = vars[i];
977 }
978 for (int j = 0; j < vars.Length; j++)
979 {
980 vars[j] = array[paramOrder[j]];
981 }
982 }
983
984 private static bool CreateParamOrder(int[] paramOrder, ParameterInfo[] pars, string[] names)
985 {
986 bool[] array = new bool[pars.Length];
987 for (int i = 0; i < pars.Length; i++)
988 {
989 paramOrder[i] = -1;
990 }
991 for (int j = 0; j < names.Length; j++)
992 {
993 int k;
994 for (k = 0; k < pars.Length; k++)
995 {
996 if (names[j].Equals(pars[k].Name))
997 {
998 paramOrder[k] = j;
999 array[j] = true;
1000 break;
1001 }
1002 }
1003 if (k == pars.Length)
1004 {
1005 return false;
1006 }
1007 }
1008 int l = 0;
1009 for (int m = 0; m < pars.Length; m++)
1010 {
1011 if (paramOrder[m] != -1)
1012 {
1013 continue;
1014 }
1015 for (; l < pars.Length; l++)
1016 {
1017 if (!array[l])
1018 {
1019 paramOrder[m] = l;
1020 l++;
1021 break;
1022 }
1023 }
1024 }
1025 return true;
1026 }
1027
1028 internal static bool CanChangePrimitive(Type source, Type target)
1029 {
1030 if ((source == typeof(IntPtr) && target == typeof(IntPtr)) || (source == typeof(UIntPtr) && target == typeof(UIntPtr)))
1031 {
1032 return true;
1033 }
1035 Primitives primitives2 = (Primitives)(1 << (int)Type.GetTypeCode(target));
1036 return (primitives & primitives2) != 0;
1037 }
1038}
static unsafe Array CreateInstance(Type elementType, int length)
Definition Array.cs:473
static unsafe void Copy(Array sourceArray, Array destinationArray, int length)
Definition Array.cs:624
static readonly DBNull Value
Definition DBNull.cs:8
BinderState(int[] argsMap, int originalSize, bool isParamArray)
static MethodBase FindMostDerivedNewSlotMeth(MethodBase[] match, int cMatches)
static int FindMostSpecificMethod(MethodBase m1, int[] paramOrder1, Type paramArrayType1, MethodBase m2, int[] paramOrder2, Type paramArrayType2, Type[] types, object[] args)
override FieldInfo BindToField(BindingFlags bindingAttr, FieldInfo[] match, object value, CultureInfo cultureInfo)
static int GetHierarchyDepth(Type t)
static bool CanChangePrimitive(Type source, Type target)
override PropertyInfo SelectProperty(BindingFlags bindingAttr, PropertyInfo[] match, Type returnType, Type[] indexes, ParameterModifier[] modifiers)
override MethodBase SelectMethod(BindingFlags bindingAttr, MethodBase[] match, Type[] types, ParameterModifier[] modifiers)
override void ReorderArgumentArray(ref object[] args, object state)
static int FindMostSpecificProperty(PropertyInfo cur1, PropertyInfo cur2)
static int FindMostSpecific(ParameterInfo[] p1, int[] paramOrder1, Type paramArrayType1, ParameterInfo[] p2, int[] paramOrder2, Type paramArrayType2, Type[] types, object[] args)
override MethodBase BindToMethod(BindingFlags bindingAttr, MethodBase[] match, ref object[] args, ParameterModifier[] modifiers, CultureInfo cultureInfo, string[] names, out object state)
static void ReorderParams(int[] paramOrder, object[] vars)
static bool CreateParamOrder(int[] paramOrder, ParameterInfo[] pars, string[] names)
static MethodBase ExactBinding(MethodBase[] match, Type[] types, ParameterModifier[] modifiers)
override object ChangeType(object value, Type type, CultureInfo cultureInfo)
static int FindMostSpecificType(Type c1, Type c2, Type t)
static bool CompareMethodSig(MethodBase m1, MethodBase m2)
static readonly Primitives[] s_primitiveConversions
static PropertyInfo ExactPropertyBinding(PropertyInfo[] match, Type returnType, Type[] types, ParameterModifier[] modifiers)
static int FindMostSpecificField(FieldInfo cur1, FieldInfo cur2)
static readonly Empty Value
Definition Empty.cs:5
virtual ParameterInfo[] GetParametersNoCopy()
virtual bool IsDefined(Type attributeType, bool inherit)
static string Arg_MustBeType
Definition SR.cs:302
static string MissingMember
Definition SR.cs:1628
static string NotSupported_ChangeType
Definition SR.cs:1662
static string MissingField
Definition SR.cs:1618
static string Arg_AmbiguousMatchException
Definition SR.cs:62
static string Arg_EmptyArray
Definition SR.cs:134
Definition SR.cs:7
Type? GetElementType()
virtual bool IsAssignableFrom([NotNullWhen(true)] Type? c)
Definition Type.cs:1561
bool IsClass
Definition Type.cs:184
static ? Type GetType(string typeName, bool throwOnError, bool ignoreCase)
Definition Type.cs:408
static readonly object Missing
Definition Type.cs:21
Type UnderlyingSystemType
Definition Type.cs:61
bool IsCOMObject
Definition Type.cs:223
override bool Equals(object? o)
Definition Type.cs:1113
static TypeCode GetTypeCode(Type? type)
Definition Type.cs:919
virtual bool IsInstanceOfType([NotNullWhen(true)] object? o)
Definition Type.cs:1020
bool IsPrimitive
Definition Type.cs:231
bool IsRuntimeImplemented()
Definition Type.cs:470
bool IsByRef
Definition Type.cs:73