private static ExpressionStatementSyntax _CreateParallelFor(ForStatementSyntax statement) { var variable = statement.Declaration.Variables.Single(); var from = variable.Initializer.Value; // The analyzer only allows binary expressions where the upper bound is on the left hand-side. // Therefore, no further checks are necessary. var binary = (BinaryExpressionSyntax)statement.Condition; var to = binary.Right; if (binary.IsKind(SyntaxKind.LessThanOrEqualExpression)) { // TODO maybe try to reduce resulting expressions like ...-1+1 to = SyntaxFactory.BinaryExpression(SyntaxKind.AddExpression, to, _CreateOneLiteral()); } return(SyntaxFactory.ExpressionStatement( SyntaxFactory.InvocationExpression( MemberAccessGenerator.CreateMemberAccess("Parallel", "For"), ArgumentListGenerator.CreateArgumentList(from, to, LambdaGenerator.CreateLambdaOrDelegate(variable.Identifier, statement.Statement)) ) ).WithTriviaFrom(statement)); }
public void CreateMemberAccessWithThreeMembers() { Assert.AreEqual("Task.Factory.Scheduler.Id", MemberAccessGenerator.CreateMemberAccess("Task", "Factory", "Scheduler", "Id").ToString()); }
public void CreateMemberAccessWithOneMember() { Assert.AreEqual("Console.WriteLine", MemberAccessGenerator.CreateMemberAccess("Console", "WriteLine").ToString()); }
public void CreateMemberAccessWithTwoMembers() { Assert.AreEqual("Task.Factory.StartNew", MemberAccessGenerator.CreateMemberAccess("Task", "Factory", "StartNew").ToString()); }