Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ SelectMethod() [1/2]

override MethodBase System.DefaultBinder.SelectMethod ( BindingFlags bindingAttr,
MethodBase[] match,
Type[] types,
ParameterModifier[] modifiers )
inlinesealedinherited

Definition at line 404 of file DefaultBinder.cs.

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 {
497 throw new AmbiguousMatchException(SR.Arg_AmbiguousMatchException);
498 }
499 return array2[num2];
500 }
501 }
502 }
static int FindMostSpecificMethod(MethodBase m1, int[] paramOrder1, Type paramArrayType1, MethodBase m2, int[] paramOrder2, Type paramArrayType2, Type[] types, object[] args)
static bool CanChangePrimitive(Type source, Type target)
virtual ParameterInfo[] GetParametersNoCopy()

References System.SR.Arg_AmbiguousMatchException, System.SR.Arg_EmptyArray, System.SR.Arg_MustBeType, System.array, System.DefaultBinder.CanChangePrimitive(), System.DefaultBinder.FindMostSpecificMethod(), System.Reflection.MethodBase.GetParametersNoCopy(), System.Type.IsAssignableFrom(), System.Type.IsPrimitive, System.match, System.Reflection.ParameterInfo.ParameterType, System.type, and System.Type.UnderlyingSystemType.