Is there a way, to cast a lambda expression (efficiently) to a function pointer, delegate*<?,?,?,?,>?

Viewed 81

I currently do this code here:

 Fp = (delegate* unmanaged<????bool>)Expression.Lambda(func).Compile().Method.MethodHandle.GetFunctionPointer();

But I would like actually to avoid the temporary creation of the Delegate Expression.Lambda(func).Compile() and rather go instantly to something like this:

Expression.Lambda(func).MakeFuncPointer()

That would be cool, so we can instant translate it to that, without the need of creating the temp delegate, which is extra allocation cost.

The <,,,,> or <???> are placeholders for the exact type matching of the Lambda, you can freely assume they are both of equal signature!

Apparently, I get a runtime-exception: "The requested operation is invalid for DynamicMethod".

0 Answers
Related