I'm trying to get the function pointer of a method inside of a generic class. I've been using MethodInfo.MethodHandle.GetFunctionPointer() to do so, but as I've been working with generic classes recently, the above methodology has been working the way I thought it would.
Consider the following:
public class Example<T>
{
public bool doSomething()
{
/*some work*/
return true;
}
}
The following all return the same memory address:
typeof(Example<int>).GetMethod("doSomething").MethodHandle.GetFunctionPointer()
typeof(Example<bool>).GetMethod("doSomething").MethodHandle.GetFunctionPointer()
typeof(Example<SomeClass>).GetMethod("doSomething").MethodHandle.GetFunctionPointer()
I'm not sure why this is. Can anyone explain it to me? Is there really only one version of that function within memory?
Surely this raises some eyebrows. I am working on a modifying a game's code without access to the source. Injecting code this way is common practice in this line of work. The EULA for the game specifically allows for such injection as well, so long as the original dll file is not directly modified.