The problem
I need to generate a fast reflection based method during runtime. Therefore i looked into dynamic methods. The problem is im stuck with my limited knowledge.
Thats the method i need to call with a dynamic method.
public struct EntityManager{
public void SetComponent<T>(Entity e, T component) where T : struct, IComponentData{
// Simplified
}
}
// The component to pass in it
public struct ComponentExample : IComponentData{}
And im stuck with the part where i need to pass the Entity and the Component into the method. I just cant find any example on how we do that.
var dm = new DynamicMethod(
"SetComponent",
typeof(void),
new [] { typeof(Entity), typeof(ComponentExample)},
false
);
var il = dm.GetILGenerator();
// Emit Entity & the ComponentExample ???
il.EmitCall(OpCodes.Call, genericMethod, null);
il.Emit(OpCodes.Ret);
The question
How exactly do we "emit" an struct ( Entity ) and an object into the DynamicMethod for executing it ? Glad for any help on this topic !
"emit" an struct ( Entity ) and an object into the DynamicMethodcan we have some pseudo-code as to what it is supposed to do: is it just passing empty objects and structs with the default constructors, or do you have specific constructors you need to call?ldarg.0,ldarg.1is probably all you need if those types are parameters. But if you know the types that you need for the generic method, why can you not call it directly? Can you elaborate more on where you get the type parameters, I think there is a much better methodobjectvariable?), how you intend to pass it to the DynamicMethod, bearing in mind you don't know the type? Or is the DM not itself generic, in which case we are back to square one? I just don't understand how you are passing this object around?