dimanche 12 juin 2016

C# reflection to check method body of assignment to fields

For the class below :

class A
{
    private List<int> intList;
    private List<bool> boolList;

    public InitializeClass()
    {
        intList = new List<int>();
    }

}

I want to use reflection to write a linter/post compiler of sorts, to check if a certain method really have any assignment to the class' fields or not. The purpose is to automatically check my own errors. The class cannot use constructor, so I need to call InitializeClass() manually.

I have MethodInfo method and all fields of class FieldInfo[] fields that I wanted to check already but have no idea how to go from here. From the example above, it should be able to detect that I haven't assign anything to boolList in the method body.





Aucun commentaire:

Enregistrer un commentaire