Is it possible to write generic CIL instructions which will convert instances of any type (both value and reference) to System.String? In particular, I'm interested in Mono.Cecil code which will inject those instructions into a method.
Analyzing a generic method I came up with these Mono.Cecil calls: (it's supposed to convert the i-th method parameter to string)
System.Reflection.MethodInfo to_string_method_info = typeof( System.Object ).GetMethod( "ToString" );
Mono.Cecil.MethodReference to_string_reference = injectible_assembly.MainModule.Import( to_string_method_info );
Mono.Cecil.TypeReference argument_type = method_definition.Parameters[ i ].ParameterType;
method_definition.Body.Instructions.Add( processor.Create( Mono.Cecil.Cil.OpCodes.Constrained, argument_type ) );
method_definition.Body.Instructions.Add( processor.Create( Mono.Cecil.Cil.OpCodes.Callvirt, to_string_reference ) );
However, when debugging I get an exception from the injected method that the "JIT compiler encountered internal limitation".