本文整理汇总了C#中LiteralExpressionSyntax.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# LiteralExpressionSyntax.ToString方法的具体用法?C# LiteralExpressionSyntax.ToString怎么用?C# LiteralExpressionSyntax.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LiteralExpressionSyntax
的用法示例。
在下文中一共展示了LiteralExpressionSyntax.ToString方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VisitLiteralExpression
public override SyntaxNode VisitLiteralExpression(LiteralExpressionSyntax node)
{
if (node.IsKind(SyntaxKind.StringLiteralExpression)
&& node.ToString().IndexOf('\n') >= 0)
{
node = node.WithAdditionalAnnotations(LayoutAnnotations.MultiLineConstructAnnotation);
}
return base.VisitLiteralExpression(node);
}
示例2: VisitLiteralExpression
public override void VisitLiteralExpression(LiteralExpressionSyntax node)
{
if (node.Kind() == SyntaxKind.StringLiteralExpression)
cb.Append("std::string(").Append(node.ToString()).Append(")");
else
cb.Append(node.ToString());
}
示例3: LiteralExpression
public static string LiteralExpression(LiteralExpressionSyntax expression)
{
switch (expression.CSharpKind())
{
//Swift doesn't use the same 'c' character literal syntax, instead you create a String and type annotate it as a Character
case SyntaxKind.CharacterLiteralExpression:
//this is sketch, probably shouldn't use char literals o.o
return '"' + expression.Token.ValueText.Replace("\\'", "'").Replace("\"", "\\\"") + '"';
default:
return expression.ToString();
}
}
示例4: Go
public static void Go(OutputWriter writer, LiteralExpressionSyntax expression, bool isConst, bool inSwitch=false)
{
var str = expression.ToString();
if (str.Trim() == "null")
{
writer.Write("null");
return;
}
if (str.StartsWith("@\""))
{
str = "r" + FixUpLiterals(EncodeNonAsciiCharacters(FixUpLiterals(str.Substring(1))));
/*str = "\"" +
str.RemoveFromStartOfString("@\"")
.RemoveFromEndOfString("\"")
.Replace("\\", "\\\\")
.Replace("\"\"", "\\\"")
.Replace("\r\n", "\\n") + "\"";*/
}
var typeInfo = TypeProcessor.GetTypeInfo(expression);
var type = typeInfo.Type;
if (type == null)
type = typeInfo.ConvertedType;
if (type != null && type.SpecialType == SpecialType.System_String)
{
if (str.Contains("\\u") || str.Contains("\\x"))
str = FixUpLiterals(EncodeNonAsciiCharacters(FixUpLiterals(str)));
if (str == "null")
{
if (inSwitch)
writer.Write("-1");
else
writer.Write("null");
}
else if (inSwitch)
{
writer.Write(str);
}
else
{
}
writer.Write("_S(" + str + ")");
}
else if (type != null && type.Name == "Nullable")//Nullable Support
{
var atype = TypeProcessor.ConvertType(type);
writer.Write(atype + "()");
}
else
{
if(type.SpecialType==SpecialType.System_Boolean)
writer.Write(str);
else if (type.SpecialType == SpecialType.System_Char)
{
if(str.Contains("\\u") || str.Contains("\\x"))
writer.Write("cast(wchar)"+FixUpCharacterLiteral(str));
else
{
writer.Write(str);
}
}
else
{
//No need to convert these ... lets just put the correct suffix ourselves
if (typeInfo.ConvertedType != typeInfo.Type && typeInfo.ConvertedType.IsPrimitiveInteger() && typeInfo.Type.IsPrimitiveInteger())
{
writer.Write("cast({0})",TypeProcessor.ConvertType(typeInfo.ConvertedType)); //TODO: add better, less clumsy conversion
}
// //Number literals //TODO: make these convert to D Literal Suffixes
// var suffix = realTypeSuffixes.FirstOrDefault (j => str.EndsWith (j));
// if (suffix != null)
// str = str.Replace(suffix,drealTypeSuffixes[Array.IndexOf(realTypeSuffixes,suffix)]);
// else
// {
// suffix = integerTypeSuffixes.FirstOrDefault (j => str.EndsWith (j));
// if (suffix != null)
// str = str.Replace(suffix,dintegerTypeSuffixes[Array.IndexOf(integerTypeSuffixes,suffix)]);
// }
writer.Write(str);
}
}
}
示例5: IsNoCandidateDiagnostic
private static bool IsNoCandidateDiagnostic(LiteralExpressionSyntax literal)
{
return literal.ToString() != "\"\"" ||
literal.Ancestors().OfType<AttributeArgumentSyntax>().Any() ||
literal.Ancestors().OfType<ParameterListSyntax>().Any();
}