本文整理汇总了C#中Microsoft.CodeAnalysis.Solution.GetProjectDependencyGraph方法的典型用法代码示例。如果您正苦于以下问题:C# Solution.GetProjectDependencyGraph方法的具体用法?C# Solution.GetProjectDependencyGraph怎么用?C# Solution.GetProjectDependencyGraph使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.CodeAnalysis.Solution
的用法示例。
在下文中一共展示了Solution.GetProjectDependencyGraph方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FindTarget
public async Task<Target> FindTarget(Solution solution)
{
if (solution == null)
{
return new Target();
}
var classDeclarationSyntaxes = solution.GetProjectDependencyGraph().GetTopologicallySortedProjects()
.Select(async projectId =>
{
var project = solution.GetProject(projectId);
var compilation = (await project.GetCompilationAsync());
return compilation;
})
.Select(compilationTask => compilationTask.Result)
.Where(compilation => GetClassDeclarationSyntaxes(compilation).Any())
.Select(compilation => new Target() { Compilation = compilation, Node = GetClassDeclarationSyntaxes(compilation).First() });
var foundNamespaceDeclarationSyntax = new Target();
if (classDeclarationSyntaxes.Any())
{
foundNamespaceDeclarationSyntax = classDeclarationSyntaxes.First();
}
return foundNamespaceDeclarationSyntax;
}
示例2: FindSource
public async Task<SyntaxNode> FindSource(Solution solution, string activeDocument, int cursorPosition)
{
if (solution == null || string.IsNullOrEmpty(activeDocument) || cursorPosition < 0)
{
return null;
}
var compilationTasks = solution.GetProjectDependencyGraph().GetTopologicallySortedProjects()
.Select(projectId =>
{
var project = solution.GetProject(projectId);
var compilation = project.GetCompilationAsync();
return compilation;
});
foreach (var task in compilationTasks)
{
task.Wait();
}
var invocationExpressions = compilationTasks
.Select(task => task.Result)
.SelectMany(compilation => compilation.SyntaxTrees)
.Where(compilation => FileNameComparer.SameFile(compilation.FilePath, activeDocument))
.Select(syntaxTree => syntaxTree.GetRoot())
.SelectMany(root => root.DescendantNodesAndSelf())
.Where(syntaxNode => syntaxNode.IsKind(Microsoft.CodeAnalysis.CSharp.SyntaxKind.MethodDeclaration))
.SelectMany(methodDeclaration => methodDeclaration.DescendantNodesAndSelf())
.Where(IsSource)
.Where(syntaxNode => syntaxNode.Span.Contains(cursorPosition));
SyntaxNode foundInvocationExpression = null;
if (invocationExpressions.Any())
{
foundInvocationExpression = invocationExpressions.First();
}
return foundInvocationExpression;
}
示例3: InnerCalculate
private async Task<IProjectMetric> InnerCalculate(Project project, Task<Compilation> compilationTask, Solution solution)
{
if (project == null)
{
return null;
}
var compilation = await compilationTask.ConfigureAwait(false);
var metricsTask = _metricsCalculator.Calculate(project, solution);
IEnumerable<string> dependencies;
if (solution != null)
{
var dependencyGraph = solution.GetProjectDependencyGraph();
dependencies = dependencyGraph.GetProjectsThatThisProjectTransitivelyDependsOn(project.Id)
.Select<ProjectId, Project>(id => solution.GetProject(id))
.SelectMany(x => x.MetadataReferences.Select(y => y.Display).Concat(new[] { x.AssemblyName }));
}
else
{
dependencies = project.AllProjectReferences.SelectMany(x => x.Aliases)
.Concat(project.MetadataReferences.Select(y => y.Display));
}
var assemblyTypes = compilation.Assembly.TypeNames;
var metrics = (await metricsTask.ConfigureAwait(false)).AsArray();
var internalTypesUsed = from metric in metrics
from coupling in metric.ClassCouplings
where coupling.Assembly == project.AssemblyName
select coupling;
var relationalCohesion = (internalTypesUsed.Count() + 1.0) / assemblyTypes.Count;
return new ProjectMetric(project.Name, metrics, dependencies, relationalCohesion);
}
示例4: GetProviderContainingEntryPointAsync
internal static async Task<Tuple<ProjectCodeProvider, IMethodSymbol, SyntaxTree>> GetProviderContainingEntryPointAsync(Solution solution, CancellationToken cancellationToken = default(CancellationToken))
{
var projectIDs = solution.GetProjectDependencyGraph().GetTopologicallySortedProjects(cancellationToken);
var continuations = new BlockingCollection<Task<Tuple<ProjectCodeProvider, IMethodSymbol>>>();
foreach (var projectId in projectIDs)
{
var project = solution.GetProject(projectId);
var pair = await ProjectCodeProvider.GetProviderContainingEntryPointAsync(project);
if (pair != null)
{
return pair;
}
}
//foreach (var continuation in continuations) {
// var pair = await continuation;
// if (pair != null)
// {
// return pair;
// }
//}
return null;
}