| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent a21c797 commit 77e9bcb
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,6 +9,12 @@ | |||
| 9 | 9 | namespace Python.Runtime | |
| 10 | 10 | { | |
| 11 | 11 | using MaybeMethodBase = MaybeMethodBase<MethodBase>; | |
| 12 | + | ||
| 13 | + public delegate void MethodBinderCoerceBindDelegate( | ||
| 14 | + Dictionary<string, PyObject> arguments, | ||
| 15 | + MethodBase[] methods, | ||
| 16 | + ref MethodBase? foundBinding); | ||
| 17 | + | ||
| 12 | 18 | /// <summary> | |
| 13 | 19 | /// A MethodBinder encapsulates information about a (possibly overloaded) | |
| 14 | 20 | /// managed method, and is responsible for selecting the right method given | |
@@ -516,7 +522,7 @@ public MismatchedMethod(Exception exception, MethodBase mb) | |||
| 516 | 522 | } | |
| 517 | 523 | } | |
| 518 | 524 | ||
| 519 | - return new Binding(mi, target, margs, outs); | ||
| 525 | + return CoerceResult(new Binding(mi, target, margs, outs)); | ||
| 520 | 526 | } | |
| 521 | 527 | else if (matchGenerics && isGeneric) | |
| 522 | 528 | { | |
@@ -528,7 +534,7 @@ public MismatchedMethod(Exception exception, MethodBase mb) | |||
| 528 | 534 | MethodInfo[] overloads = MatchParameters(methods, types); | |
| 529 | 535 | if (overloads.Length != 0) | |
| 530 | 536 | { | |
| 531 | - return Bind(inst, args, kwargDict, overloads, matchGenerics: false); | ||
| 537 | + return CoerceResult(Bind(inst, args, kwargDict, overloads, matchGenerics: false)); | ||
| 532 | 538 | } | |
| 533 | 539 | } | |
| 534 | 540 | if (mismatchedMethods.Count > 0) | |
@@ -537,6 +543,19 @@ public MismatchedMethod(Exception exception, MethodBase mb) | |||
| 537 | 543 | Exceptions.SetError(aggregateException); | |
| 538 | 544 | } | |
| 539 | 545 | return null; | |
| 546 | + | ||
| 547 | + Binding? CoerceResult(Binding? binding) | ||
| 548 | + { | ||
| 549 | + if (binding is not null) | ||
| 550 | + { | ||
| 551 | + var foundMethod = binding.info; | ||
| 552 | + MethodBinderEvents.CoerceBind?.Invoke(kwargDict, methods, ref foundMethod); | ||
| 553 | + if (foundMethod is null) | ||
| 554 | + return null; | ||
| 555 | + } | ||
| 556 | + | ||
| 557 | + return binding; | ||
| 558 | + } | ||
| 540 | 559 | } | |
| 541 | 560 | ||
| 542 | 561 | static AggregateException GetAggregateException(IEnumerable<MismatchedMethod> mismatchedMethods) | |
@@ -1068,4 +1087,9 @@ static internal class ParameterInfoExtensions | |||
| 1068 | 1087 | } | |
| 1069 | 1088 | } | |
| 1070 | 1089 | } | |
| 1090 | + | ||
| 1091 | + public static class MethodBinderEvents | ||
| 1092 | + { | ||
| 1093 | + public static MethodBinderCoerceBindDelegate? CoerceBind; | ||
| 1094 | + } | ||
| 1071 | 1095 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments