@@ -278,6 +278,23 @@ internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw, MethodBase info)
278
278
return Bind ( inst , args , kw , info , null ) ;
279
279
}
280
280
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
+
281
298
internal Binding Bind ( IntPtr inst , IntPtr args , IntPtr kw , MethodBase info , MethodInfo [ ] methodinfo )
282
299
{
283
300
// 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
310
327
_methods = GetMethods ( ) ;
311
328
}
312
329
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 ) ;
317
331
318
332
// TODO: Clean up
319
333
foreach ( MethodBase mi in _methods )
@@ -342,35 +356,33 @@ internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw, MethodBase info, Meth
342
356
continue ;
343
357
}
344
358
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 ) ;
347
361
}
348
362
if ( argMatchedMethods . Count ( ) > 0 )
349
363
{
350
364
// Order matched methods by number of kwargs matched and get the max possible number
351
365
// 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 ;
353
367
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 )
357
370
{
358
- if ( argMatchedTuple . Item1 == bestKwargMatchCount )
371
+ if ( testMatch . KwargsMatched == bestKwargMatchCount )
359
372
{
360
- bestKwargMatches . Add ( argMatchedTuple ) ;
373
+ bestKwargMatches . Add ( testMatch ) ;
361
374
}
362
375
}
363
376
364
377
// 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 ;
366
379
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 )
370
382
{
371
- if ( testTuple . Item2 == fewestDefaultsRequired )
383
+ if ( testMatch . DefaultsNeeded == fewestDefaultsRequired )
372
384
{
373
- bestDefaultsMatches . Add ( testTuple ) ;
385
+ bestDefaultsMatches . Add ( testMatch ) ;
374
386
}
375
387
}
376
388
@@ -388,10 +400,10 @@ internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw, MethodBase info, Meth
388
400
// in the case of (a) we're done by default. For (b) regardless of which
389
401
// method we choose, all arguments are specified _and_ can be converted
390
402
// 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 ;
395
407
396
408
object target = null ;
397
409
if ( ! mi . IsStatic && inst != IntPtr . Zero )
0 commit comments