@@ -278,6 +278,23 @@ internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw, MethodBase info)
278278 return Bind ( inst , args , kw , info , null ) ;
279279 }
280280
281+ private readonly struct MatchedMethod {
282+ public MatchedMethod ( int kwargsMatched , int defaultsNeeded , object [ ] margs , int outs , MethodBase mb )
283+ {
284+ KwargsMatched = kwargsMatched ;
285+ DefaultsNeeded = defaultsNeeded ;
286+ ManagedArgs = margs ;
287+ Outs = outs ;
288+ Method = mb ;
289+ }
290+
291+ public int KwargsMatched { get ; }
292+ public int DefaultsNeeded { get ; }
293+ public object [ ] ManagedArgs { get ; }
294+ public int Outs { get ; }
295+ public MethodBase Method { get ; }
296+ }
297+
281298 internal Binding Bind ( IntPtr inst , IntPtr args , IntPtr kw , MethodBase info , MethodInfo [ ] methodinfo )
282299 {
283300 // loop to find match, return invoker w/ or /wo error
@@ -310,10 +327,7 @@ internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw, MethodBase info, Meth
310327 _methods = GetMethods ( ) ;
311328 }
312329
313- // List of tuples containing methods that have matched based on arguments.
314- // Format of tuple is: Number of kwargs matched, defaults needed, margs, outs, method base for matched method
315- List < Tuple < int , int , object [ ] , int , MethodBase > > argMatchedMethods =
316- new List < Tuple < int , int , object [ ] , int , MethodBase > > ( _methods . Length ) ;
330+ List < MatchedMethod > argMatchedMethods = new List < MatchedMethod > ( _methods . Length ) ;
317331
318332 // TODO: Clean up
319333 foreach ( MethodBase mi in _methods )
@@ -342,35 +356,33 @@ internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw, MethodBase info, Meth
342356 continue ;
343357 }
344358
345- var matchedMethodTuple = Tuple . Create ( kwargsMatched , defaultsNeeded , margs , outs , mi ) ;
346- argMatchedMethods . Add ( matchedMethodTuple ) ;
359+ var matchedMethod = new MatchedMethod ( kwargsMatched , defaultsNeeded , margs , outs , mi ) ;
360+ argMatchedMethods . Add ( matchedMethod ) ;
347361 }
348362 if ( argMatchedMethods . Count ( ) > 0 )
349363 {
350364 // Order matched methods by number of kwargs matched and get the max possible number
351365 // of kwargs matched
352- var bestKwargMatchCount = argMatchedMethods . OrderBy ( ( x ) => x . Item1 ) . Reverse ( ) . ToArray ( ) [ 0 ] . Item1 ;
366+ var bestKwargMatchCount = argMatchedMethods . OrderBy ( ( x ) => x . KwargsMatched ) . Reverse ( ) . ToArray ( ) [ 0 ] . KwargsMatched ;
353367
354- List < Tuple < int , int , object [ ] , int , MethodBase > > bestKwargMatches =
355- new List < Tuple < int , int , object [ ] , int , MethodBase > > ( argMatchedMethods . Count ( ) ) ;
356- foreach ( Tuple < int , int , object [ ] , int , MethodBase > argMatchedTuple in argMatchedMethods )
368+ List < MatchedMethod > bestKwargMatches = new List < MatchedMethod > ( argMatchedMethods . Count ( ) ) ;
369+ foreach ( MatchedMethod testMatch in argMatchedMethods )
357370 {
358- if ( argMatchedTuple . Item1 == bestKwargMatchCount )
371+ if ( testMatch . KwargsMatched == bestKwargMatchCount )
359372 {
360- bestKwargMatches . Add ( argMatchedTuple ) ;
373+ bestKwargMatches . Add ( testMatch ) ;
361374 }
362375 }
363376
364377 // Order by the number of defaults required and find the smallest
365- var fewestDefaultsRequired = bestKwargMatches . OrderBy ( ( x ) => x . Item2 ) . ToArray ( ) [ 0 ] . Item2 ;
378+ var fewestDefaultsRequired = bestKwargMatches . OrderBy ( ( x ) => x . DefaultsNeeded ) . ToArray ( ) [ 0 ] . DefaultsNeeded ;
366379
367- List < Tuple < int , int , object [ ] , int , MethodBase > > bestDefaultsMatches =
368- new List < Tuple < int , int , object [ ] , int , MethodBase > > ( bestKwargMatches . Count ( ) ) ;
369- foreach ( Tuple < int , int , object [ ] , int , MethodBase > testTuple in bestKwargMatches )
380+ List < MatchedMethod > bestDefaultsMatches = new List < MatchedMethod > ( bestKwargMatches . Count ( ) ) ;
381+ foreach ( MatchedMethod testMatch in bestKwargMatches )
370382 {
371- if ( testTuple . Item2 == fewestDefaultsRequired )
383+ if ( testMatch . DefaultsNeeded == fewestDefaultsRequired )
372384 {
373- bestDefaultsMatches . Add ( testTuple ) ;
385+ bestDefaultsMatches . Add ( testMatch ) ;
374386 }
375387 }
376388
@@ -388,10 +400,10 @@ internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw, MethodBase info, Meth
388400 // in the case of (a) we're done by default. For (b) regardless of which
389401 // method we choose, all arguments are specified _and_ can be converted
390402 // from python to C# so picking any will suffice
391- Tuple < int , int , object [ ] , int , MethodBase > bestMatch = bestDefaultsMatches . ToArray ( ) [ 0 ] ;
392- var margs = bestMatch . Item3 ;
393- var outs = bestMatch . Item4 ;
394- var mi = bestMatch . Item5 ;
403+ MatchedMethod bestMatch = bestDefaultsMatches . ToArray ( ) [ 0 ] ;
404+ var margs = bestMatch . ManagedArgs ;
405+ var outs = bestMatch . Outs ;
406+ var mi = bestMatch . Method ;
395407
396408 object target = null ;
397409 if ( ! mi . IsStatic && inst != IntPtr . Zero )
0 commit comments