11using System ;
22using System . Collections ;
33using System . Collections . Concurrent ;
4+ using System . Collections . Generic ;
45using System . Diagnostics ;
56using System . Linq ;
67using System . Reflection ;
@@ -167,16 +168,16 @@ internal MethodBase[] GetMethods()
167168 // I'm sure this could be made more efficient.
168169 list . Sort ( new MethodSorter ( ) ) ;
169170 methods = ( MethodBase [ ] ) list . ToArray ( typeof ( MethodBase ) ) ;
170- pyArgumentConverter = this . GetArgumentConverter ( ) ;
171+ pyArgumentConverter = GetArgumentConverter ( this . methods ) ;
171172 init = true ;
172173 }
173174 return methods ;
174175 }
175176
176- IPyArgumentConverter GetArgumentConverter ( ) {
177+ static IPyArgumentConverter GetArgumentConverter ( IEnumerable < MethodBase > methods ) {
177178 IPyArgumentConverter converter = null ;
178179 Type converterType = null ;
179- foreach ( MethodBase method in this . methods )
180+ foreach ( MethodBase method in methods )
180181 {
181182 PyArgConverterAttribute attribute = TryGetArgConverter ( method . DeclaringType ) ;
182183 if ( converterType == null )
@@ -326,14 +327,17 @@ internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw, MethodBase info, Meth
326327 MethodBase [ ] _methods = null ;
327328 var pynargs = ( int ) Runtime . PyTuple_Size ( args ) ;
328329 var isGeneric = false ;
330+ IPyArgumentConverter argumentConverter ;
329331 if ( info != null )
330332 {
331333 _methods = new MethodBase [ 1 ] ;
332334 _methods . SetValue ( info , 0 ) ;
335+ argumentConverter = GetArgumentConverter ( _methods ) ;
333336 }
334337 else
335338 {
336339 _methods = GetMethods ( ) ;
340+ argumentConverter = this . pyArgumentConverter ;
337341 }
338342
339343 // TODO: Clean up
@@ -351,7 +355,7 @@ internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw, MethodBase info, Meth
351355 continue ;
352356 }
353357 var outs = 0 ;
354- var margs = this . TryConvertArguments ( pi , paramsArray , args , pynargs , defaultArgList ,
358+ var margs = TryConvertArguments ( pi , paramsArray , argumentConverter , args , pynargs , defaultArgList ,
355359 needsResolution : _methods . Length > 1 ,
356360 outs : out outs ) ;
357361
@@ -406,7 +410,8 @@ internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw, MethodBase info, Meth
406410 /// <param name="needsResolution"><c>true</c>, if overloading resolution is required</param>
407411 /// <param name="outs">Returns number of output parameters</param>
408412 /// <returns>An array of .NET arguments, that can be passed to a method.</returns>
409- object [ ] TryConvertArguments ( ParameterInfo [ ] pi , bool paramsArray ,
413+ static object [ ] TryConvertArguments ( ParameterInfo [ ] pi , bool paramsArray ,
414+ IPyArgumentConverter argumentConverter ,
410415 IntPtr args , int pyArgCount ,
411416 ArrayList defaultArgList ,
412417 bool needsResolution ,
@@ -436,7 +441,7 @@ object[] TryConvertArguments(ParameterInfo[] pi, bool paramsArray,
436441 : Runtime . PyTuple_GetItem ( args , paramIndex ) ;
437442
438443 bool isOut ;
439- if ( ! this . pyArgumentConverter . TryConvertArgument (
444+ if ( ! argumentConverter . TryConvertArgument (
440445 op , parameter . ParameterType , needsResolution ,
441446 out margs [ paramIndex ] , out isOut ) )
442447 {
0 commit comments