本文整理汇总了C#中SyntaxToken.IsVerbatimIdentifier方法的典型用法代码示例。如果您正苦于以下问题:C# SyntaxToken.IsVerbatimIdentifier方法的具体用法?C# SyntaxToken.IsVerbatimIdentifier怎么用?C# SyntaxToken.IsVerbatimIdentifier使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SyntaxToken
的用法示例。
在下文中一共展示了SyntaxToken.IsVerbatimIdentifier方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateNewIdentifierTokenFromToken
private SyntaxToken CreateNewIdentifierTokenFromToken(SyntaxToken originalToken, bool escape)
{
var isVerbatimIdentifier = originalToken.IsVerbatimIdentifier();
if (isVerbatimIdentifier == escape)
{
return originalToken;
}
var unescapedText = isVerbatimIdentifier ? originalToken.ToString().Substring(1) : originalToken.ToString();
return escape
? originalToken.CopyAnnotationsTo(SyntaxFactory.VerbatimIdentifier(originalToken.LeadingTrivia, unescapedText, originalToken.ValueText, originalToken.TrailingTrivia))
: originalToken.CopyAnnotationsTo(SyntaxFactory.Identifier(originalToken.LeadingTrivia, SyntaxKind.IdentifierToken, unescapedText, originalToken.ValueText, originalToken.TrailingTrivia));
}
示例2: RenameToken
private SyntaxToken RenameToken(SyntaxToken oldToken, SyntaxToken newToken, string prefix, string suffix)
{
var parent = oldToken.Parent;
string currentNewIdentifier = _isVerbatim ? _replacementText.Substring(1) : _replacementText;
var oldIdentifier = newToken.ValueText;
var isAttributeName = SyntaxFacts.IsAttributeName(parent);
if (isAttributeName)
{
Debug.Assert(_renamedSymbol.IsAttribute() || _aliasSymbol.Target.IsAttribute());
if (oldIdentifier != _renamedSymbol.Name)
{
string withoutSuffix;
if (currentNewIdentifier.TryGetWithoutAttributeSuffix(out withoutSuffix))
{
currentNewIdentifier = withoutSuffix;
}
}
}
else
{
if (!string.IsNullOrEmpty(prefix))
{
currentNewIdentifier = prefix + currentNewIdentifier;
}
if (!string.IsNullOrEmpty(suffix))
{
currentNewIdentifier = currentNewIdentifier + suffix;
}
}
// determine the canonical identifier name (unescaped, no unicode escaping, ...)
string valueText = currentNewIdentifier;
var kind = SyntaxFacts.GetKeywordKind(currentNewIdentifier);
if (kind != SyntaxKind.None)
{
valueText = SyntaxFacts.GetText(kind);
}
else
{
var parsedIdentifier = SyntaxFactory.ParseName(currentNewIdentifier);
if (parsedIdentifier.IsKind(SyntaxKind.IdentifierName))
{
valueText = ((IdentifierNameSyntax)parsedIdentifier).Identifier.ValueText;
}
}
// TODO: we can't use escaped unicode characters in xml doc comments, so we need to pass the valuetext as text as well.
// <param name="\u... is invalid.
// if it's an attribute name we don't mess with the escaping because it might change overload resolution
newToken = _isVerbatim || (isAttributeName && oldToken.IsVerbatimIdentifier())
? newToken = newToken.CopyAnnotationsTo(SyntaxFactory.VerbatimIdentifier(newToken.LeadingTrivia, currentNewIdentifier, valueText, newToken.TrailingTrivia))
: newToken = newToken.CopyAnnotationsTo(SyntaxFactory.Identifier(newToken.LeadingTrivia, SyntaxKind.IdentifierToken, currentNewIdentifier, valueText, newToken.TrailingTrivia));
if (_replacementTextValid)
{
if (newToken.IsVerbatimIdentifier())
{
// a reference location should always be tried to be unescaped, whether it was escaped before rename
// or the replacement itself is escaped.
newToken = newToken.WithAdditionalAnnotations(Simplifier.Annotation);
}
else
{
var semanticModel = GetSemanticModelForNode(parent, _speculativeModel ?? _semanticModel);
newToken = Simplification.CSharpSimplificationService.TryEscapeIdentifierToken(newToken, parent, semanticModel);
}
}
return newToken;
}
示例3: IsVerbatimIdentifier
public bool IsVerbatimIdentifier(SyntaxToken token)
{
return token.IsVerbatimIdentifier();
}