[Mono-list] Embedded API: Method signature not found with generic parameter

Robert Jordan robertj at gmx.net
Thu Jul 11 20:22:42 UTC 2013


On 11.07.2013 21:08, mugginsoft wrote:
> Robert Jordan wrote
>> Oops, my test actually passes with:
>>
>> 	":ToList(System.Collections.Generic.IEnumerable`1
>> <TSource>
>> )"
>
> Thanks. I thought I had tried all the combinations - I should have been more
> methodical! I wonder why the method name querying functions provide a
> different sig?
>
> However (one last however):
>
> Calling the method results in:
>
> * Assertion at method-to-ir.c:6281, condition `!sig->has_type_parameters'
> not met

You must "inflate" the generic method upon invocation.

IIRC, there is no function in the embedded API which does this.

What I'm doing is:

1) implement a helper method in C#:


public static IntPtr MakeGenericMethod(MethodInfo method, Type[] parms)
{
	// See MSDN's MethodInfo.MakeGenericMethod docs
	return method.MakeGenericMethod (parms).MethodHandle.Value;
}


2) mono_runtime_invoke () this method with the following args:

   arg 1: the result of mono_method_get_object(the_method). This is
          actually a MethodInfo object.
   arg 2: a System.Type array containing MonoReflectionTypes* with the
	 types to be substituted. A MonoReflectionType* is obtained
	 with mono_type_get_object ().

The helper method returns a MonoMethod* which you can invoke
like a normal non-generic method.


You can do this work solely in C/C++, but using a helper method
would save you some hundred line of convoluted embedded API
invocations. You can save even more code by implementing a couple
of MakeGenericMethod variants that don't need an array argument:

public static IntPtr MakeGenericMethod_1(MethodInfo method, Type parm0)
{
	return method.MakeGenericMethod (parm0).MethodHandle.Value;
}

public static IntPtr MakeGenericMethod_2(MethodInfo method, Type parm0, 
Type parm1)
{
	return method.MakeGenericMethod (parm0, parm1).MethodHandle.Value;
}

public static IntPtr MakeGenericMethod_3(MethodInfo method, Type parm0, 
Type parm1, Type parm2)
{
	return method.MakeGenericMethod (parm0, parm1, parm2).MethodHandle.Value;
}


Robert



More information about the Mono-list mailing list