MSIL - how do you invoke a private method from MSIL?

后端 未结 3 1178
礼貌的吻别
礼貌的吻别 2021-01-02 20:04

I\'m writing a \"weak event factory\" - code which converts any Delegate into a new delegate with an identical signature, but with implementing a WeakReference on the target

3条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-02 20:49

    The solution (to my particular problem), was to used delegates instead of direct method calls. You can comfortably construct an open delegate and pass it to the IL code, and then when the IL code invokes the delegate's Invoke method, the JIT accepts the pattern as legal and allows the invoke of the private methods.

    Like I said, this is a solution (which happily allows runtime-generated code to call private methods), though it still doesn't explain how technolgies like Expression Trees and Reflection manage to call private methods.

提交回复
热议问题