本文整理汇总了C#中SyntaxToken.GetText方法的典型用法代码示例。如果您正苦于以下问题:C# SyntaxToken.GetText方法的具体用法?C# SyntaxToken.GetText怎么用?C# SyntaxToken.GetText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SyntaxToken
的用法示例。
在下文中一共展示了SyntaxToken.GetText方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VisitToken
public override void VisitToken(SyntaxToken token)
{
VisitLeadingTrivia(token);
bool isProcessed = false;
if (token.IsKeyword())
{
writeDelegate(TokenKind.None, token.GetText(), null);
isProcessed = true;
}
else
{
switch (token.Kind)
{
case SyntaxKind.IdentifierToken:
writeDelegate(this.GetTokenKind(token), token.GetText(), token.Span.Start);
isProcessed = true;
break;
default:
writeDelegate(TokenKind.None, token.GetText(), null);
isProcessed = true;
break;
}
}
if (!isProcessed)
{
writeDelegate(TokenKind.None, token.GetText(), null);
}
base.VisitTrailingTrivia(token);
}
示例2: VisitToken
public override void VisitToken(SyntaxToken token)
{
if (token.GetText() == parameter.Text)
{
switch (searchTokenKind)
{
case TokenKind.MethodCall:
var methodDeclarationSyntax = token.Parent as MethodDeclarationSyntax;
var methodSymbol = this.semanticModel.GetDeclaredSymbol(methodDeclarationSyntax);
if (methodSymbol.ToString() == parameter.FullyQualifiedName)
{
symbolFoundDelegate(token.SyntaxTree.GetLineSpan(token.Span, false).StartLinePosition.Line);
}
break;
case TokenKind.ObjectCreation:
var classDeclarationSyntax = token.Parent as ClassDeclarationSyntax;
var classSymbol = this.semanticModel.GetDeclaredSymbol(classDeclarationSyntax);
if (classSymbol.ToString() == parameter.FullyQualifiedName)
{
symbolFoundDelegate(token.SyntaxTree.GetLineSpan(token.Span, false).StartLinePosition.Line);
}
break;
}
}
base.VisitToken(token);
}
示例3: VisitToken
public override void VisitToken(SyntaxToken token)
{
VisitLeadingTrivia(token);
bool isProcessed = false;
if (token.IsKeyword())
{
writeDelegate(TokenKind.None, token.GetText(), null);
isProcessed = true;
}
else
{
switch (token.Kind)
{
case SyntaxKind.IdentifierToken:
TokenKind tokenKind = this.GetTokenKind(token);
if (tokenKind == TokenKind.None)
{
writeDelegate(TokenKind.None, token.GetText(), null);
}
else
{
try
{
string fullyQualifiedNamed = this.GetFullyQualifiedName(tokenKind, token);
writeDelegate(tokenKind, token.GetText(), fullyQualifiedNamed);
}
catch (Exception)
{
writeDelegate(TokenKind.None, token.GetText(),null);
}
}
isProcessed = true;
break;
default:
writeDelegate(TokenKind.None,token.GetText(), null);
isProcessed = true;
break;
}
}
if (!isProcessed)
{
writeDelegate(TokenKind.None,token.GetText(), null);
}
base.VisitTrailingTrivia(token);
}
示例4: VisitToken
protected override SyntaxToken VisitToken(SyntaxToken token)
{
if (token.Kind == SyntaxKind.IdentifierToken && token.GetText() == this.oldName)
return Syntax.Identifier(token.LeadingTrivia,
this.newName,
token.TrailingTrivia);
return token;
}
示例5: GetFullyQualifiedName
private string GetFullyQualifiedName(TokenKind tokenKind, SyntaxToken token)
{
string result = token.GetText();
SymbolInfo symbolInfo;
switch (tokenKind)
{
case TokenKind.MethodCall:
case TokenKind.PropertyDeclaration:
case TokenKind.Parameter:
case TokenKind.VariableDeclaration:
case TokenKind.MemberAccess:
var identifierSyntax = token.Parent as IdentifierNameSyntax;
symbolInfo = this.semanticModel.GetSymbolInfo(identifierSyntax);
if (symbolInfo.Symbol != null)
{
result = symbolInfo.Symbol.ToString();
}
break;
case TokenKind.ObjectCreation:
var objectCreationSyntax = token.Parent.Parent as ObjectCreationExpressionSyntax;
symbolInfo = this.semanticModel.GetSymbolInfo(objectCreationSyntax);
if (symbolInfo.Symbol != null)
{
result = symbolInfo.Symbol.ToString();
}
break;
case TokenKind.None:
default:
break;
}
return result;
}
示例6: GetTypeName
/* Get the RefactoringType name of a declaration. */
private string GetTypeName(SyntaxToken token)
{
var parent = GetParentDeclaratorOrParameter(token);
logger.Debug("Declared Token: " + token.GetText());
logger.Debug("Declarator: " + parent.GetText());
if (parent != null)
{
// If this declaration is an instance declarator, get the type name of the
// declarator.
if (parent.Kind == SyntaxKind.VariableDeclarator)
{
return GetDeclaratorTypeName(parent);
}
// If the declaration is a parameter, get the type name of the parameter.
if (parent.Kind == SyntaxKind.Parameter)
{
return GetParameterTypeName(parent);
}
// If the symbol is the identifier in the for each loop.
if (parent.Kind == SyntaxKind.ForEachStatement)
{
return GetForEachIdentifierTypeName(parent);
}
}
// If not declarator, return object.
return OBJECT;
}