当前位置: 首页>>代码示例>>C#>>正文


C# Solution.GetProjectDependencyGraph方法代码示例

本文整理汇总了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;
        }
开发者ID:cristiingineru,项目名称:ExpressionViewer,代码行数:25,代码来源:ExpressionSearcher.cs

示例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;
        }
开发者ID:cristiingineru,项目名称:ExpressionViewer,代码行数:38,代码来源:ExpressionSearcher.cs

示例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);
		}
开发者ID:jjrdk,项目名称:ArchiMetrics,代码行数:37,代码来源:ProjectMetricsCalculator.cs

示例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;
		}
开发者ID:TubaKayaDev,项目名称:Call-Graph-Builder-DotNet,代码行数:24,代码来源:ProjectCodeProvider.cs


注:本文中的Microsoft.CodeAnalysis.Solution.GetProjectDependencyGraph方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。