@@ -22,10 +22,48 @@ public static class BinderUtilities
2222 /// <returns> The index of the selected method. </returns>
2323 public static int ResolveOverloads ( RuntimeMethodHandle [ ] methodHandles , ScriptEngine engine , object thisValue , object [ ] arguments )
2424 {
25+ object thisUnwrapped = thisValue ;
26+ if ( thisUnwrapped is Library . ClrInstanceWrapper )
27+ {
28+ thisUnwrapped = ( thisUnwrapped as Library . ClrInstanceWrapper ) . WrappedInstance ;
29+ }
30+ Type unwrappedType ;
31+ if ( thisUnwrapped is Library . ClrStaticTypeWrapper )
32+ {
33+ unwrappedType = ( thisUnwrapped as Library . ClrStaticTypeWrapper ) . WrappedType ;
34+ }
35+ else if ( thisUnwrapped is Library . ClrInstanceTypeWrapper )
36+ {
37+ unwrappedType = ( thisUnwrapped as Library . ClrInstanceTypeWrapper ) . WrappedType ;
38+ }
39+ else
40+ {
41+ unwrappedType = thisUnwrapped . GetType ( ) ;
42+ }
43+
2544 // Get methods from the handles.
2645 var methods = new BinderMethod [ methodHandles . Length ] ;
2746 for ( int i = 0 ; i < methodHandles . Length ; i ++ )
28- methods [ i ] = new BinderMethod ( MethodBase . GetMethodFromHandle ( methodHandles [ i ] ) ) ;
47+ {
48+ if ( unwrappedType . IsGenericType )
49+ {
50+ // Generic methods. Works for classes which are generic.
51+ methods [ i ] = new BinderMethod (
52+ MethodBase . GetMethodFromHandle ( methodHandles [ i ] , unwrappedType . TypeHandle ) ) ;
53+ }
54+ else if ( unwrappedType . BaseType . IsGenericType )
55+ {
56+ // Generic methods. Works for classes which inherit generic type.
57+ // For example: class AlternateViewCollection : Collection<AlternateView>
58+ methods [ i ] = new BinderMethod (
59+ MethodBase . GetMethodFromHandle ( methodHandles [ i ] ,
60+ unwrappedType . BaseType . TypeHandle ) ) ;
61+ }
62+ else
63+ {
64+ methods [ i ] = new BinderMethod ( MethodBase . GetMethodFromHandle ( methodHandles [ i ] ) ) ;
65+ }
66+ }
2967
3068 // Keep a score for each method. Add one point if a type conversion is required, or
3169 // a million points if a type conversion cannot be performed.
0 commit comments