private Boolean ExistLocalVariable(StatementSyntax statement)
 {
     return(statement.DescendantNodesAndTokens().Any(n => {
         var token = n.AsToken();
         if (token == null)
         {
             return false;
         }
         return token.Text == localVaribleName;
     }));
 }
Esempio n. 2
0
 private static IEnumerable <SyntaxNodeOrToken> GetReferences(string variableName, StatementSyntax statement)
 {
     return(statement.DescendantNodesAndTokens().Where(x =>
     {
         if (x.IsNode && x.IsKind(SyntaxKind.IdentifierName))
         {
             return x.ToString() == variableName;
         }
         else
         {
             return false;
         }
     }));
 }
Esempio n. 3
0
        private static Boolean AllTypeInStatementIsValid(StatementSyntax statement, SemanticModel semanticModel)
        {
            var listNodes = statement.DescendantNodes().ToList();
            var member    = listNodes.OfType <MemberAccessExpressionSyntax>().FirstOrDefault();
            var typeList  = member != null?member.Name.DescendantNodesAndSelf().OfType <TypeSyntax>() : listNodes.OfType <TypeSyntax>();

            if (!AllTypeIsExist(typeList.ToList(), semanticModel))
            {
                return(false);
            }
            if (typeList.First().GetLastToken().GetNextToken().Kind() != SyntaxKind.SemicolonToken)
            {
                return(false);
            }
            var beginTokenInType = member != null?member.GetFirstToken() : typeList.First().GetFirstToken();

            if (statement.DescendantNodesAndTokens().Contains(beginTokenInType.GetPreviousToken()))
            {
                return(false);
            }
            return(true);
        }