本文整理汇总了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));
}
示例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();
}
示例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;
}