Open bacar opened 3 years ago
Yeah so I found a solution, Go into MethodInvocationEmmiter class and change the ctor-
public MethodInvocationEmitter( MethodInfo methodInfo, Flags bindingFlags )
: this( methodInfo.DeclaringType, bindingFlags, methodInfo.Name, methodInfo.GetParameters().ToTypeArray(), methodInfo ) {
}
into this-
public MethodInvocationEmitter( MethodInfo methodInfo, Flags bindingFlags )
: this( methodInfo.DeclaringType, methodInfo.GetGenericArguments(), bindingFlags, methodInfo.Name, methodInfo.GetParameters().ToTypeArray(), methodInfo ) {
}
And add a new private ctor-
private MethodInvocationEmitter( Type targetType, Type[] genericTypes, Flags bindingFlags, string name, Type[] parameterTypes, MemberInfo methodInfo )
: base(new CallInfo(targetType, genericTypes, bindingFlags, MemberTypes.Method, name, parameterTypes, methodInfo, true)) {
}
I was blown away at how easy of a solution this was.
Hi,
The following test fails:
The second call
gen2.Call()
ends up invoking the first method, with the wrong (int) type parameters. The problem is reversed if you swap the two assert lines to make thedouble
one come first.The problem appears to be in the
MethodInvocationEmitter
ctor - it passesnull
as thegenericTypes
argument to theCallInfo
constructor, which means that the generic type arguments of the method are ignored when looking up an appropriate delegate from theBaseEmitter.cache