Exemple #1
0
 public override SyntaxNode VisitArgument(ArgumentSyntax node)
 {
     if (node.Expression.Kind().Equals(SyntaxKind.NumericLiteralExpression))
     {
         NumberOperations        ne      = new NumberOperations();
         LiteralExpressionSyntax les     = (LiteralExpressionSyntax)node.Expression;
         ExpressionSyntax        es      = SyntaxFactory.ParseExpression(ne.UnwrapNumber(les.Token.ValueText));
         ArgumentSyntax          newNode = node.WithExpression(es);
         return(base.VisitArgument(node.ReplaceNode(node, newNode)));
     }
     return(base.VisitArgument(node));
 }
Exemple #2
0
        public override SyntaxNode VisitLiteralExpression(LiteralExpressionSyntax node)
        {
            if (node.Kind().Equals(SyntaxKind.NumericLiteralExpression))
            {
                if (int.TryParse(node.Token.ValueText, out int result))
                {
                    LiteralExpressionSyntax newExp;
                    if (result < 10)
                    {
                        newExp = node.WithToken(SyntaxFactory.ParseToken(NumberOperations.DecToBin(node.Token.ValueText)));
                    }
                    else
                    {
                        newExp = node.WithToken(SyntaxFactory.ParseToken(NumberOperations.DecToHex(node.Token.ValueText)));
                    }

                    var newNode = node.ReplaceNode(node, newExp);
                    return(base.VisitLiteralExpression(newNode));
                }
            }

            return(base.VisitLiteralExpression(node));
        }