Look if a method is called inside a method using reflection

后端 未结 3 1020
情话喂你
情话喂你 2020-11-30 08:26

I\'m working with reflection and currently have a MethodBody. How do I check if a specific method is called inside the MethodBody?

Assembly assembly = Assemb         


        
3条回答
  •  [愿得一人]
    2020-11-30 08:46

    Before it generates code, it must check if it already exists

    There are a few cases where catching an exception is way cheaper than preventing it from being generated. This is a prime example. You can get the IL for the method body but Reflection is not a disassembler. Nor is a disassembler a real fix, you'd have the disassemble the entire call tree to implement your desired behavior. After all, a method call in the body could itself call a method, etcetera. It is just much simpler to catch the exception that the jitter will throw when it compiles the IL.

提交回复
热议问题