Exemplo n.º 1
0
        private bool HasInvocationToAnyOf([ItemNotNull] ImmutableArray <IMethodSymbol> methodsToInvoke,
                                          [NotNull] IMethodSymbol methodToAnalyze, SymbolAnalysisContext context)
        {
            IOperation operation = methodToAnalyze.TryGetOperationBlockForMethod(context.Compilation, context.CancellationToken);

            if (operation != null)
            {
                var walker = new MethodInvocationWalker(methodsToInvoke);
                walker.Visit(operation);
                return(walker.HasFoundInvocation);
            }

            return(false);
        }
Exemplo n.º 2
0
        public void Visit(string path)
        {
            var project     = Solution.LoadStandAloneProject(path);
            var compilation = project.GetCompilation();

            foreach (var tree in compilation.SyntaxTrees)
            {
                var methodInvocationWalker = new MethodInvocationWalker(_graphClient, compilation.GetSemanticModel(tree));
                methodInvocationWalker.Visit(tree.GetRoot() as SyntaxNode);

                var methodInvokedStoredProcedureWalker = new MethodInvokesStoredProcedureWalker(_graphClient, compilation.GetSemanticModel(tree));
                methodInvokedStoredProcedureWalker.Visit(tree.GetRoot() as SyntaxNode);
            }
        }
Exemplo n.º 3
0
        public void FindAllInvocationsToMethodsFromAParticularNamespace()
        {
            var tree = SyntaxFactory.ParseSyntaxTree(@"
using System;
using System.Threading.Tasks;
class Program
{
    static void Main()
    {
        Action a = () => {};
        var t = Task.Factory.StartNew(a);
        t.Wait();
        Console.WriteLine(a.ToString());
 
        a = () =>
        {
            t = new Task(a);
            t.Start();
            t.Wait();
        };
        a();
    }
}");
            var compilation = CSharpCompilation.Create("MyCompilation")
                .AddReferences(Mscorlib)
                .AddSyntaxTrees(tree);
            var model = compilation.GetSemanticModel(tree);

            // Instantiate MethodInvocationWalker (below) and tell it to find invocations to methods from the System.Threading.Tasks namespace.
            var walker = new MethodInvocationWalker()
            {
                SemanticModel = model,
                Namespace = "System.Threading.Tasks"
            };

            walker.Visit(tree.GetRoot());
            Assert.Equal(@"
Line 8: Task.Factory.StartNew(a)
Line 9: t.Wait()
Line 14: new Task(a)
Line 15: t.Start()
Line 16: t.Wait()", walker.Results.ToString());
        }