Подскажите, пожалуйста, как посчитать количество итераций цикла do while с помощью Roslyn? Нужен семантический анализатор, который бы определял итерации.
using System;
using System.Linq;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
namespace testAnalyzer
{
class Program
{
static void Main(string[] args)
{
var code = @"
public void FindI()
{
int i = 0;
int a = 17;
do
{
a+=9;
i++;
}
while (a<104);
}";
var syntaxTree = CSharpSyntaxTree.ParseText(code);
var doStatement = syntaxTree
.GetRoot()
.DescendantNodes()
.OfType<DoStatementSyntax>()
.First();
//??????????
Console.WriteLine("num of iterations: " );
Console.ReadKey();
}
}
}
проверить код можете здесь
i-1 - кол-во итераций
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
namespace Rextester
{
public class Program
{
public static void Main(string[] args)
{
int i = 0;
int test = 0;
do
{
test+=20;
i++;
if(test > 1000) break;
}
while(true);
Console.Write((i-1).ToString());
}
}
}
Продвижение своими сайтами как стратегия роста и независимости