@@ -33,7 +33,8 @@ public static int ResolveOverloads(RuntimeMethodHandle[] methodHandles, ScriptEn
3333 const int disqualification = 65536 ;
3434 for ( int i = 0 ; i < methods . Length ; i ++ )
3535 {
36- foreach ( var argument in methods [ i ] . GetArguments ( arguments . Length ) )
36+ IEnumerable < BinderArgument > binderArguments = methods [ i ] . GetArguments ( arguments . Length ) ;
37+ foreach ( var argument in binderArguments )
3738 {
3839 // Get the input parameter.
3940 object input ;
@@ -147,6 +148,21 @@ public static int ResolveOverloads(RuntimeMethodHandle[] methodHandles, ScriptEn
147148 lowestIndices = _LowestIndices ( methods , demeritPoints , out lowestScore ) ;
148149 }
149150
151+ // Try to get the method with most close arguments count
152+ if ( lowestIndices . Count > 1 )
153+ {
154+ for ( int i = 0 ; i < demeritPoints . Length ; i ++ )
155+ {
156+ demeritPoints [ i ] = disqualification ;
157+ }
158+ for ( int i = 0 ; i < lowestIndices . Count ; i ++ )
159+ {
160+ int index = lowestIndices [ i ] ;
161+ demeritPoints [ index ] = _CalcArgumentsPoint ( methods [ index ] , arguments . Length ) ;
162+ }
163+ lowestIndices = _LowestIndices ( methods , demeritPoints , out lowestScore ) ;
164+ }
165+
150166 // Throw an error if the match is ambiguous.
151167 if ( lowestIndices . Count > 1 )
152168 {
@@ -215,6 +231,13 @@ private static int _CalcMethodDistance(Type thisType, Type declaringType)
215231
216232 return result ;
217233 }
234+
235+
236+ private static int _CalcArgumentsPoint ( BinderMethod method , int argumentsCount )
237+ {
238+ int points = Math . Max ( method . GetParameters ( ) . Length - argumentsCount , 0 ) ;
239+ return points ;
240+ }
218241 }
219242
220243}
0 commit comments