Property / Method inlining and impact on Reflection

痞子三分冷 提交于 2019-12-04 02:50:37

JIT compiler operates at runtime and it can't rewrite metadata information stored in the assembly. And reflection reads assembly to access this metadata. So there are no impact from JIT-compiler to reflection.

EDIT: Actually there are couple of places when C# compiler itself "inlines" some information during compilation. For example, constants, enums and default arguments are "inlined" so you can't access them during reflection. But it definitely not related to your particular case.

Yeah when I think about it more I guess only way inlining properties could fail INotifyPropertyChanged interface correct work would be if you were using a reflection based method used like

public Count
{
get {return m_Count;}
 set { m_Count=value;
      GetCurrentPropertyNameUsingReflectionAndNotifyItChanged();}
}

If used like you suggest indeed metadata exists in assembly and property name will be successfully taken from there.

Got us both thinking though.

I personally agree with @Sergey:

Considering that inlining happens on JIT compiler side, but metadata generated before, it shouldn't inpact on reflection in any way. By the way, good question, like it +1

Expression trees can't be in-lined anyway since they are a representation of the expression (abstract syntax tree) rather than the expression itself.

Delegates, even if they can be in-lined, will still carry the data about the method and target being called in their properties.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!