@@ -452,9 +452,9 @@ internal Binding Bind(BorrowedReference inst, BorrowedReference args, BorrowedRe
452452 // Relevant method variables
453453 var mi = methodInformation . MethodBase ;
454454 var pi = methodInformation . ParameterInfo ;
455+ var paramNames = methodInformation . ParametersNames ;
455456 int pyArgCount = ( int ) Runtime . PyTuple_Size ( args ) ;
456457
457-
458458 // Special case for operators
459459 bool isOperator = OperatorMethod . IsOperatorMethod ( mi ) ;
460460 // Binary operator methods will have 2 CLR args but only one Python arg
@@ -479,15 +479,12 @@ internal Binding Bind(BorrowedReference inst, BorrowedReference args, BorrowedRe
479479
480480 // Must be done after IsOperator section
481481 int clrArgCount = pi . Length ;
482- var parametersSnakeCasedNames = kwArgDict == null || methodInformation . IsOriginal
483- ? null
484- : pi . Select ( p => p . Name . ToSnakeCase ( ) ) . ToArray ( ) ;
485482
486483 if ( CheckMethodArgumentsMatch ( clrArgCount ,
487484 pyArgCount ,
488485 kwArgDict ,
489486 pi ,
490- parametersSnakeCasedNames ,
487+ paramNames ,
491488 out bool paramsArray ,
492489 out ArrayList defaultArgList ) )
493490 {
@@ -506,13 +503,8 @@ internal Binding Bind(BorrowedReference inst, BorrowedReference args, BorrowedRe
506503 object arg ; // Python -> Clr argument
507504
508505 // Check our KWargs for this parameter
509- var hasNamedParam = false ;
510- if ( kwArgDict != null )
511- {
512- var paramName = methodInformation . IsOriginal ? parameter . Name : parametersSnakeCasedNames [ paramIndex ] ;
513- hasNamedParam = kwArgDict . TryGetValue ( paramName , out tempPyObject ) ;
514- }
515- if ( tempPyObject != null )
506+ bool hasNamedParam = kwArgDict == null ? false : kwArgDict . TryGetValue ( paramNames [ paramIndex ] , out tempPyObject ) ;
507+ if ( tempPyObject != null )
516508 {
517509 op = tempPyObject ;
518510 }
@@ -776,11 +768,16 @@ static BorrowedReference HandleParamsArray(BorrowedReference args, int arrayStar
776768 /// This helper method will perform an initial check to determine if we found a matching
777769 /// method based on its parameters count and type <see cref="Bind(IntPtr,IntPtr,IntPtr,MethodBase,MethodInfo[])"/>
778770 /// </summary>
771+ /// <remarks>
772+ /// We required both the parameters info and the parameters names to perform this check.
773+ /// The CLR method parameters info is required to match the parameters count and type.
774+ /// The names are required to perform an accurate match, since the method can be the snake-cased version.
775+ /// </remarks>
779776 private bool CheckMethodArgumentsMatch ( int clrArgCount ,
780777 int pyArgCount ,
781778 Dictionary < string , PyObject > kwargDict ,
782779 ParameterInfo [ ] parameterInfo ,
783- string [ ] parametersSnakeCasedNames ,
780+ string [ ] parameterNames ,
784781 out bool paramsArray ,
785782 out ArrayList defaultArgList )
786783 {
@@ -803,9 +800,7 @@ private bool CheckMethodArgumentsMatch(int clrArgCount,
803800 {
804801 // If the method doesn't have all of these kw args, it is not a match
805802 // Otherwise just continue on to see if it is a match
806- if ( ! kwargDict . All ( x => parametersSnakeCasedNames == null
807- ? parameterInfo . Any ( pi => x . Key == pi . Name )
808- : parametersSnakeCasedNames . Any ( paramName => x . Key == paramName ) ) )
803+ if ( ! kwargDict . All ( x => parameterNames . Any ( paramName => x . Key == paramName ) ) )
809804 {
810805 return false ;
811806 }
@@ -825,7 +820,7 @@ private bool CheckMethodArgumentsMatch(int clrArgCount,
825820 defaultArgList = new ArrayList ( ) ;
826821 for ( var v = pyArgCount ; v < clrArgCount && match ; v ++ )
827822 {
828- if ( kwargDict != null && kwargDict . ContainsKey ( parametersSnakeCasedNames == null ? parameterInfo [ v ] . Name : parametersSnakeCasedNames [ v ] ) )
823+ if ( kwargDict != null && kwargDict . ContainsKey ( parameterNames [ v ] ) )
829824 {
830825 // we have a keyword argument for this parameter,
831826 // no need to check for a default parameter, but put a null
@@ -996,6 +991,8 @@ internal class MethodInformation
996991
997992 public bool IsOriginal { get ; }
998993
994+ public string [ ] ParametersNames { get ; }
995+
999996 public MethodInformation ( MethodBase methodBase , ParameterInfo [ ] parameterInfo )
1000997 : this ( methodBase , parameterInfo , true )
1001998 {
@@ -1006,6 +1003,15 @@ public MethodInformation(MethodBase methodBase, ParameterInfo[] parameterInfo, b
10061003 MethodBase = methodBase ;
10071004 ParameterInfo = parameterInfo ;
10081005 IsOriginal = isOriginal ;
1006+
1007+ if ( isOriginal )
1008+ {
1009+ ParametersNames = ParameterInfo . Select ( pi => pi . Name ) . ToArray ( ) ;
1010+ }
1011+ else
1012+ {
1013+ ParametersNames = ParameterInfo . Select ( pi => pi . Name . ToSnakeCase ( ) ) . ToArray ( ) ;
1014+ }
10091015 }
10101016
10111017 public override string ToString ( )
0 commit comments