Cannot decompile ldtoken instruction
There's no straightforward translation of ldtoken to C# (unless it's a type token -> typeof), but we should try to figure out some way of representing these.
See #892 for previous discussion. As for why selecting the right method can be tricky, see https://stackoverflow.com/questions/3631547/select-right-generic-method-with-reflection
See https://github.com/dotnet/csharplang/issues/191
Note that ldtoken and ldftn are slightly different issues.
In particular for ldftn there's another proposal: https://github.com/dotnet/csharplang/blob/master/proposals/function-pointers.md
We could just start emitting code according to one of these proposals, and hope that they get implemented at some point in time.
Alternatively, this idea should still work:
I think a possible way to translate ldtoken for now would be:
new DelegateType(Method).MethodInfo.MethodHandlewhere DelegateType is a delegate that matches the method's signature (if there's no ref/out involved,Action<>/Func<>will do the job; otherwise the decompiler will have to declare a new delegate). Only problem is if it's an instance method belonging to another class, as we need an instance for creating a delegate.
I guess a different idea would be to use a lambda: LdToken((InstanceType x) => x.Method(default(ParamType1), ...))
I think it might even be possible to provide a real implementation for LdToken by extracting the token via expression tree.