简体   繁体   中英

How do I use Reflection to get the fields of a method?

How can I user reflection to get the fields inside a method? I tried to use the MethodInfo and then GetFields but the values returned are not the fields I defined within the method.

For example, using the code below, how would I get the FieldInfo for LineNo?

    private void MyMethod()
    {
        int LineNo = 0;
    }

Thanks

With reflection you can't get values of field in code of function,

You can get the values of field of Class/Object .

  1. These are not fields but local variables.
  2. At best you can get IL of method body. If you can somehow parse that you should be able to get your hands at all the locals declared in the method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM