本文整理汇总了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);
}
示例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;
}
示例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;
}