当前位置: 首页>>代码示例>>C#>>正文


C# LiteralExpressionSyntax.GetText方法代码示例

本文整理汇总了C#中LiteralExpressionSyntax.GetText方法的典型用法代码示例。如果您正苦于以下问题:C# LiteralExpressionSyntax.GetText方法的具体用法?C# LiteralExpressionSyntax.GetText怎么用?C# LiteralExpressionSyntax.GetText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在LiteralExpressionSyntax的用法示例。


在下文中一共展示了LiteralExpressionSyntax.GetText方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: VisitLiteralExpression

            public override SyntaxNode VisitLiteralExpression(LiteralExpressionSyntax node)
            {
                if (node.Kind != SyntaxKind.StringLiteralExpression)
                    return node;

                var variables = InterpolationUtils.EnumerateVariables(node.GetText().ToString()).Distinct().ToArray();
                var arguments = string.Join(", ", variables);
                var formatString = node.GetText().ToString();

                for (int i = 0; i < variables.Length; i++) {
                    formatString = formatString.Replace("$" + variables[0], "{" + i + "}");
                }

                return Syntax.ParseExpression(string.Format("string.Format({0}, {1})", formatString, arguments));
            }
开发者ID:JackWangCUMT,项目名称:RoslynStringInterpolation,代码行数:15,代码来源:StringInterpolator.cs

示例2: EmitLiteralExpression

        private string EmitLiteralExpression(LiteralExpressionSyntax node)
        {
            /*
            switch (node.Kind)
            {
                case SyntaxKind.NumericLiteralExpression:
                    _writer.Write(node.GetText());
                    break;

                case SyntaxKind.StringLiteralExpression:
                    _writer.Write("\"{0}\"", node.GetText());
                    break;
            }
            */

            return node.GetText();
        }
开发者ID:IgorShare,项目名称:jinx,代码行数:17,代码来源:JavaScriptWalker.cs

示例3: VisitLiteralExpression

        public override SyntaxNode VisitLiteralExpression(LiteralExpressionSyntax node)
        {
            switch (node.Kind())
            {
                case SyntaxKind.FalseLiteralExpression:
                    _output.Write(node, "false");
                    break;

                case SyntaxKind.TrueLiteralExpression:
                    _output.Write(node, "true");
                    break;

                case SyntaxKind.NullLiteralExpression:
                    _output.Write(node, "null");
                    break;

                case SyntaxKind.NumericLiteralExpression:
                    string num = node.GetText().ToString().Trim();//Note:Keep everything, e.g. prefix 0, in C#, it has no meaning, but it means octet in js
                    if (!char.IsNumber(num[num.Length - 1]))//Note:Remove postfix, since C# has l,m etc as postfix.
                    {
                        num = num.Substring(0, num.Length - 1);
                    }
                    _output.Write(node, num);
                    break;

                case SyntaxKind.StringLiteralExpression:
                    string str = node.Token.ValueText.Bracketing(StringPair.DoubleQuote);
                    if (str[0] == '@')
                    {
                        str = str.Substring(1);

                        this.AppendCompileIssue(node, IssueType.Warning, IssueId.StringPrefixIgnore);
                    }
                    _output.Write(node, str);
                    break;

                case SyntaxKind.CharacterLiteralExpression:
                    _output.Write(node, node.Token.ValueText.Bracketing(StringPair.SingleQuote));
                    break;

                default:
                    this.AppendCompileIssue(node, IssueType.Error, IssueId.UnknownExpressionType, node.Kind());
                    break;
            }

            return node;
        }
开发者ID:rexzh,项目名称:SharpJs,代码行数:47,代码来源:Rewriter_Expression.cs


注:本文中的LiteralExpressionSyntax.GetText方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。