lundi 4 février 2019

C# Retrieving metadata of fields referenced in a method

I have a MethodInfo object and would like to inspect it to determine which local fields the method references. For instance:

class MyClass
{
  private int MyField;

  public int MyMethod()
  {
    return MyField *= 2;
  }
}

Given a MethodInfo that referrences MyClass.MyMethod(), is there any way I can determine that it references MyField (and only that field) without having to do something insane, such as obtaining the raw bytecode and parsing it?





Aucun commentaire:

Enregistrer un commentaire