Endless loop code analysis with FxCop Introspection

I am trying to write my own rule for analyzing FxCop code that will warn developers about methods that contain too deep nested blocks of code and will encourage them to redistribute the mess.

ex. I am trying to avoid the following situation:

if(condition)
{
   foreach(var item in items)
   {
       if(anotherCondition)
       {
           for(var product in item.Products)
           {
               // even more nested statement blocks...
           }
       }
   }
}

I get stackoverflow when I redefine a method VisitBlock(Block block)
that counts the depth of a block, because there seems to be a circular reference from one of the properties of the block to the block itself. that is, the following for some i: block.Statements [i] == block

Why is there such a circular reference? How to avoid this? Thank!

+3
source share
1 answer

, , .

  • VisitXXX . IL . , , FxCop ?
  • , , , , SourceContext method.Body '{' '}' . '{' '}'. , ?
0

Source: https://habr.com/ru/post/1791086/


All Articles