c# - How to find nodes before a given node with Roslyn? -
i developing roslyn analyzer detect use of specific method, method1
. want allow use of method in for
, while
loops, , create issue in other cases in code.
how can that? code developed detects method1
everywhere. want each time find function, check if it's in loop or not, , generate error if not in loop.
the method call descendant of loop declaration if inside it. can access ancestors
property of syntaxnode
. start going among ancestors of methodinvocation
node detected until hit loop or member declaration.
if hit loop (forstatementsyntax
or whilestatementsyntax
) good. if hit memberdeclarationsyntax
node means have reached start of whatever block in method1
being called , should throw error.
at point, immediate problem mostly solved, , have decide how many corner cases want cover. if called lambda expression? if method calls method1
called loop? or recursive method?
you can detect these cases have decide if worth effort.
Comments
Post a Comment