示例#1
0
        private void RemoveAnyDescendantNodeAlreadyFound(SyntaxNode node)
        {
            DatabaseAccessingMethodCallStatement <T> existingDbAccessingCall;

            foreach (var item in node.DescendantNodes())
            {
                existingDbAccessingCall = DatabaseAccessingMethodCalls.FirstOrDefault(x => x.CompilationInfo.SyntaxNode.Span.ToString() == node.Span.ToString());
                if (existingDbAccessingCall != null)
                {
                    DatabaseAccessingMethodCalls.Remove(existingDbAccessingCall);
                }
            }
        }
示例#2
0
        private void AddDatabaseAccessingCall(SyntaxNode node, SemanticModel semanticModel, DatabaseQueryVariableDeclaration <T> queryVariableUsedInCall)
        {
            string queryText = node.GetText().ToString();
            HashSet <DatabaseEntityDeclaration <T> > databaseEntityDeclarationsUsedInQuery = GetDatabaseEntityTypesInQuery(node, semanticModel);
            var compilationInfo = node.GetCompilationInfo(semanticModel);


            if (!AncestorNodeForSameLineIsAlreadyFound(node))
            {
                RemoveAnyDescendantNodeAlreadyFound(node);
                var result = new DatabaseAccessingMethodCallStatement <T>(queryText, databaseEntityDeclarationsUsedInQuery, compilationInfo);

                if (queryVariableUsedInCall != null)
                {
                    result.SetDatabaseQueryVariable(queryVariableUsedInCall);
                }

                DatabaseAccessingMethodCalls.Add(result);
            }
        }
        private async Task ExtractDatabaseAccessingMethodCallsAsync(Solution solution)
        {
            foreach (var project in solution.Projects)
            {
                foreach (var documentId in project.DocumentIds)
                {
                    var document = solution.GetDocument(documentId);

                    SyntaxNode root = await Task.Run(() => document.GetSyntaxRootAsync());

                    SemanticModel model = await Task.Run(() => document.GetSemanticModelAsync());

                    var databaseAccessingMethodCalls = new LINQToSQLDatabaseAccessingMethodCallExtractor(model, DatabaseEntityDeclarations, DatabaseQueries, null, null, null);
                    databaseAccessingMethodCalls.Visit(root);

                    foreach (var item in databaseAccessingMethodCalls.DatabaseAccessingMethodCallsAndSyntaxNodes)
                    {
                        DatabaseAccessingMethodCalls.Add(item.Key, item.Value);
                    }
                }
            }
        }