本文整理汇总了C#中SyntaxToken.IsContextualKeyword方法的典型用法代码示例。如果您正苦于以下问题:C# SyntaxToken.IsContextualKeyword方法的具体用法?C# SyntaxToken.IsContextualKeyword怎么用?C# SyntaxToken.IsContextualKeyword使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SyntaxToken
的用法示例。
在下文中一共展示了SyntaxToken.IsContextualKeyword方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VisitToken
public override void VisitToken(SyntaxToken token)
{
SyntaxElementWithTrivia element;
if (token.IsKeyword() || token.IsContextualKeyword())
{
// Keyword
element = token.IsKind(SyntaxKind.PartialKeyword)
? ProcessPartialKeyword(token)
: new SyntaxElementWithTrivia(token, SyntaxElementKind.Keyword);
}
else if (token.IsKind(SyntaxKind.IdentifierToken))
{
// Identifier
element = ProcessSemanticSymbolIdentifier(token);
}
else if (IsStringLitteralToken(token))
{
// String litteral
element = new SyntaxElementWithTrivia(token, SyntaxElementKind.StringLitteral);
}
else
{
// Litteral
element = new SyntaxElementWithTrivia(token, SyntaxElementKind.Litteral);
}
using (_currentSyntaxElement.PostValue(element))
{
VisitLeadingTrivia(token);
VisitTrailingTrivia(token);
}
ResultsAccumulator.Add(element);
}
示例2: VisitToken
public override void VisitToken(SyntaxToken token)
{
VisitLeadingTrivia(token);
var diagnostics = Diagnostics(token);
if (diagnostics != null)
{
if (diagnostics.Any(d => d.Severity == DiagnosticSeverity.Error))
Mark(token, "error");
else
Mark(token, "warning");
}
if (token.IsKeyword() || token.IsContextualKeyword())
{
Mark(token, "keyword");
var type = GetTokenType(token);
if (type.Type != TokenType.Kind.Unknown)
ClassifyIdentifierToken(token);
}
var kind = token.CSharpContextualKind();
switch (kind)
{
case SyntaxKind.IdentifierToken:
ClassifyIdentifierToken(token); break;
case SyntaxKind.StringLiteralToken:
Mark(token, "string"); break;
case SyntaxKind.NumericLiteralToken:
Mark(token, "number"); break;
case SyntaxKind.CharacterLiteralToken:
Mark(token, "char"); break;
}
VisitTrailingTrivia(token);
}
示例3: TryGetTextForContextualKeyword
private bool TryGetTextForContextualKeyword(SyntaxToken token, Document document, ISyntaxFactsService syntaxFacts, out string text)
{
if (token.IsContextualKeyword())
{
switch (token.Kind())
{
case SyntaxKind.PartialKeyword:
if (token.Parent.GetAncestorOrThis<MethodDeclarationSyntax>() != null)
{
text = "partialmethod_CSharpKeyword";
return true;
}
else if (token.Parent.GetAncestorOrThis<ClassDeclarationSyntax>() != null)
{
text = "partialtype_CSharpKeyword";
return true;
}
break;
case SyntaxKind.WhereKeyword:
if (token.Parent.GetAncestorOrThis<TypeParameterConstraintClauseSyntax>() != null)
{
text = "whereconstraint_CSharpKeyword";
}
else
{
text = "whereclause_CSharpKeyword";
}
return true;
}
}
text = null;
return false;
}