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


C# Compilation.ContainsSyntaxTree方法代码示例

本文整理汇总了C#中Compilation.ContainsSyntaxTree方法的典型用法代码示例。如果您正苦于以下问题:C# Compilation.ContainsSyntaxTree方法的具体用法?C# Compilation.ContainsSyntaxTree怎么用?C# Compilation.ContainsSyntaxTree使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Compilation的用法示例。


在下文中一共展示了Compilation.ContainsSyntaxTree方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddToCompilation

		private static Tuple<Compilation, SyntaxTree> AddToCompilation(Compilation compilation, SyntaxTree tree)
		{
			if (!compilation.ContainsSyntaxTree(tree))
			{
				var newTree = tree;
				if (!tree.HasCompilationUnitRoot)
				{
					var childNodes = tree.GetRoot()
						.ChildNodes()
						.AsArray();
					newTree = CSharpSyntaxTree.Create(SyntaxFactory.CompilationUnit()
						.WithMembers(
							SyntaxFactory.List(childNodes.OfType<MemberDeclarationSyntax>()))
						.WithUsings(
							SyntaxFactory.List(childNodes.OfType<UsingDirectiveSyntax>()))
						.WithExterns(
							SyntaxFactory.List(childNodes.OfType<ExternAliasDirectiveSyntax>())));
				}

				var comp = compilation.AddSyntaxTrees(newTree);
				return new Tuple<Compilation, SyntaxTree>(comp, newTree);
			}

			return new Tuple<Compilation, SyntaxTree>(compilation, tree);
		}
开发者ID:henrylle,项目名称:ArchiMetrics,代码行数:25,代码来源:CodeMetricsCalculator.cs

示例2: RemoveOldTreeFromMap

                private static ImmutableDictionary<DocumentId, SyntaxTree> RemoveOldTreeFromMap(
                    Compilation newCompilation,
                    ImmutableDictionary<DocumentId, SyntaxTree> oldMap, ImmutableDictionary<DocumentId, SyntaxTree> map,
                    CancellationToken cancellationToken)
                {
                    foreach (var oldIdAndTree in oldMap)
                    {
                        cancellationToken.ThrowIfCancellationRequested();

                        // check whether new compilation still has the tree
                        if (newCompilation.ContainsSyntaxTree(oldIdAndTree.Value))
                        {
                            continue;
                        }

                        var documentId = oldIdAndTree.Key;

                        // check whether the tree has been updated
                        SyntaxTree currentTree;
                        if (!map.TryGetValue(documentId, out currentTree) ||
                            currentTree != oldIdAndTree.Value)
                        {
                            continue;
                        }

                        // this has been removed
                        map = map.Remove(documentId);
                    }

                    return map;
                }
开发者ID:jerriclynsjohn,项目名称:roslyn,代码行数:31,代码来源:SemanticModelWorkspaceServiceFactory.cs

示例3: GetModelFromSyntaxTree

        public static SemanticModel GetModelFromSyntaxTree(this SyntaxTree tree, Compilation sutCompilation)
        {
            var compilation = sutCompilation.ContainsSyntaxTree(tree)
                                ? sutCompilation
                                : sutCompilation.ExternalReferences
                                                .OfType<CompilationReference>()
                                                .Select(x => x.Compilation).FirstOrDefault(c => c.ContainsSyntaxTree(tree));

            var model = compilation?.GetSemanticModel(tree);

            return model;

        }
开发者ID:ycherkes,项目名称:MockIt,代码行数:13,代码来源:TestSemanticHelper.cs


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