示例#1
0
    private static Dictionary <string, ConditionSpecSource> ExtractConditionSourceInfo(string projectDir)
    {
        // Attempt to set the version of MSBuild.
        var visualStudioInstances = MSBuildLocator.QueryVisualStudioInstances().ToArray();
        var instance = visualStudioInstances[0];

        Console.WriteLine($"Using MSBuild at '{instance.MSBuildPath}' to load projects.");

        // NOTE: Be sure to register an instance with the MSBuildLocator
        //       before calling MSBuildWorkspace.Create()
        //       otherwise, MSBuildWorkspace won't MEF compose.
        MSBuildLocator.RegisterInstance(instance);

        var solutionPath = Path.Join(projectDir, "Core/Core.csproj");

        using var workspace = MSBuildWorkspace.Create();
        // Print message for WorkspaceFailed event to help diagnosing project load failures.
        workspace.WorkspaceFailed += (o, e) => Console.WriteLine(e.Diagnostic.Message);

        Console.WriteLine($"Loading solution '{solutionPath}'");

        // Attach progress reporter so we print projects as they are loaded.
        var project = workspace.OpenProjectAsync(solutionPath).Result;

        Console.WriteLine($"Finished loading solution '{solutionPath}'");

        var compilation = project.GetCompilationAsync().Result;

        var visitor = new SourceVisitor(projectDir);

        foreach (var sourceTree in compilation.SyntaxTrees)
        {
            if (!sourceTree.FilePath.Contains("Conditions"))
            {
                continue;
            }

            var semanticModel = compilation.GetSemanticModel(sourceTree);

            var root = sourceTree.GetRoot();
            visitor.SemanticModel = semanticModel;
            visitor.Visit(root);
        }

        return(visitor.ConditionSpecs);
    }
示例#2
0
 /// <summary>
 /// Calls visitor.Visit(LoopInvariant).
 /// </summary>
 public override void Dispatch(SourceVisitor visitor)
 {
     visitor.Visit(this);
 }
示例#3
0
            public static Expression Translate(IQueryable query, Expression expression)
            {
                var visitor = new SourceVisitor(query);

                return(visitor.Visit(expression));
            }
示例#4
0
 /// <summary>
 /// Calls visitor.Visit((SourceDeclaration)this).
 /// </summary>
 public virtual void Dispatch(SourceVisitor visitor) {
   visitor.Visit(this);
 }
示例#5
0
 /// <summary>
 /// Calls the visitor.Visit(SourceCustomAttribute) method.
 /// </summary>
 public override void Dispatch(SourceVisitor visitor)
 {
     visitor.Visit(this);
 }
示例#6
0
 /// <summary>
 /// Calls visitor.Visit((SourceDeclaration)this).
 /// </summary>
 public virtual void Dispatch(SourceVisitor visitor)
 {
     visitor.Visit(this);
 }