예제 #1
0
 public string GetNodeType(SyntaxNodeOrToken node)
 {
     if (!_nodeToTypeStringCache.TryGetValue(node, out var res))
     {
         // Handle some literal types:
         if (node.IsKind(SyntaxKind.StringLiteralToken))
         {
             res = "string";
         }
         else if (node.IsKind(SyntaxKind.CharacterLiteralToken))
         {
             res = "char";
         }
         else if (node.IsKind(SyntaxKind.NumericLiteralToken))
         {
             res = node.AsToken().Value.GetType().Name.ToLower();
         }
         else
         {
             var syntaxNode = node.IsNode ? node.AsNode() : node.AsToken().Parent;
             if (syntaxNode != null)
             {
                 ISymbol symbol = RoslynUtils.GetReferenceSymbol(syntaxNode, SemanticModel);
                 if (RoslynUtils.GetTypeSymbol(symbol, out var typeSymbol))
                 {
                     res = typeSymbol.ToString();
                 }
                 else
                 {
                     res = NOTYPE_NAME;
                 }
             }
             else
             {
                 res = NOTYPE_NAME;
             }
         }
         _nodeToTypeStringCache[node] = res;
     }
     return(res);
 }