I've been trying to create my own toy programming language for CIL using IL Reflection to generate the exes, but when Im calling a method I just doesn't seem to work.
I am using System.Reflection.ILGenerator.Emit(OpCodes.Call, MethodInfo)
.
When getting the MethodInfo
from a Type
gotten by using the typeof(something)
, it works fine, the call is sent through and it works, but when I get the Type
with the Type.GetType(string)
function, for some reason it won't generate the IL, I have tested and found that the typeof == Type.GetType
(there is no difference in the result when checking with the ==
operator).
I have looked around but can't seem to find any solution, can anyone tell me what's happening?
EDIT: here is a link to the git repo file
Code:
//Create IL Generator and standard stuff before this...
ilGenerator.Emit(OpCodes.Ldstr, "hello world"); //Push argument(s)
MethodInfo method = typeof(Console).GetMethod("WriteLine", new Type[] { typeof(string) });
MethodInfo rmethod = Type.GetType("System.Console").GetMethod("WriteLine", new Type[] { typeof(string) });
if(method == rmethod)
{
Console.WriteLine("MATCH!"); //This fires so I know they match
}
ilGenerator.Emit(OpCodes.Call, method); //This works
ilGenerator.Emit(OpCodes.Call, rmethod); //This does not... (no exceptions, but no code is generated looking with ILSpy afterwards)
I found the problem, at some point in my code before this was executed, the typebuilder.CreateType was fired, and this stoppes the il generation...
Thanks for the help though!