示例#1
0
 public override SyntaxNode VisitArgument(ArgumentSyntax node)
 {
     if (node.Expression.Kind().Equals(SyntaxKind.ParenthesizedExpression))
     {
         NumberOperations ne = new NumberOperations();
         ParenthesizedExpressionSyntax pe = (ParenthesizedExpressionSyntax)node.Expression;
         ExpressionSyntax es      = SyntaxFactory.ParseExpression(ne.ExpressionParser(pe.Expression.ToString()).ToString());
         ArgumentSyntax   newNode = node.WithExpression(es);
         return(base.VisitArgument(node.ReplaceNode(node, newNode)));
     }
     return(base.VisitArgument(node));
 }
示例#2
0
 public void ExpressionParserTest()
 {
     Assert.AreEqual(numbersExtension.ExpressionParser("(2 + 2) * (2 + 2)"), 16);
     Assert.AreEqual(numbersExtension.ExpressionParser("(64416 / 61)"), 1056);
     Assert.AreEqual(numbersExtension.ExpressionParser("(1169 + 89)"), 1258);
     Assert.AreEqual(numbersExtension.ExpressionParser("(19 * 2)"), 38);
     Assert.AreEqual(numbersExtension.ExpressionParser("(34 * 1)"), 34);
     Assert.AreEqual(numbersExtension.ExpressionParser("(-58 + 96)"), 38);
     Assert.AreEqual(numbersExtension.ExpressionParser("((1169 + 89) - (19 * 2))"), 1220);
     Assert.AreEqual(numbersExtension.ExpressionParser("(((1169 + 89) - (19 * 2)) + (34 * 1))"), 1254);
     Assert.AreEqual(numbersExtension.ExpressionParser("((64416 / 61) * (1254 * (-58 + 96)))"), 50320512);
     Assert.AreEqual(numbersExtension.ExpressionParser("((64416 / 61) * ((((1169 + 89) - (19 * 2)) + (34 * 1)) * (-58 + 96)))"), 50320512);
 }