This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var tree = CSharpSyntaxTree.ParseText(@" | |
class C | |
{ | |
void M() | |
{ | |
for (int i = 0; i < 10; i++) | |
{ | |
if (i == 3) | |
continue; | |
if (i == 8) | |
break; | |
} | |
} | |
} | |
"); | |
var Mscorlib = PortableExecutableReference.CreateFromAssembly(typeof(object).Assembly); | |
var compilation = CSharpCompilation.Create("MyCompilation", | |
syntaxTrees: new[] { tree }, references: new[] { Mscorlib }); | |
var model = compilation.GetSemanticModel(tree); | |
var firstFor = tree.GetRoot().DescendantNodes().OfType<ForStatementSyntax>().Single(); | |
ControlFlowAnalysis result = model.AnalyzeControlFlow(firstFor.Statement); | |
Console.WriteLine(result.Succeeded); //True | |
Console.WriteLine(result.ExitPoints.Count()); //2 - continue, and break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment