本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.Syntax.NamespaceDeclarationSyntax.WithUsings方法的典型用法代码示例。如果您正苦于以下问题:C# NamespaceDeclarationSyntax.WithUsings方法的具体用法?C# NamespaceDeclarationSyntax.WithUsings怎么用?C# NamespaceDeclarationSyntax.WithUsings使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.CodeAnalysis.CSharp.Syntax.NamespaceDeclarationSyntax
的用法示例。
在下文中一共展示了NamespaceDeclarationSyntax.WithUsings方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VisitNamespaceDeclaration
/// <summary>Called when the visitor visits a NamespaceDeclarationSyntax node.</summary>
public override SyntaxNode VisitNamespaceDeclaration(NamespaceDeclarationSyntax node)
{
var u = _namespaces.Select(each => SyntaxFactory.UsingDirective(SyntaxFactory.ParseName($" {each}"))
.WithLeadingTrivia(_leadingTrivia)
.WithTrailingTrivia(_trailingTrivia)
).ToArray();
node = node.AddUsings(u);
node = node.WithUsings(Sort(node.Usings));
return base.VisitNamespaceDeclaration(node);
}
示例2: AddUsing
private static NamespaceDeclarationSyntax AddUsing(NamespaceDeclarationSyntax nspaceSyntax, UsingDirectiveSyntax newUsing)
{
if (nspaceSyntax.Usings.Count > 0)
{
var lastUsing = nspaceSyntax.Usings.Last();
newUsing = newUsing
.WithLeadingTrivia(lastUsing.GetLeadingTrivia())
.WithTrailingTrivia(lastUsing.GetTrailingTrivia());
return nspaceSyntax.WithUsings(nspaceSyntax.Usings.Add(newUsing));
}
return nspaceSyntax.WithUsings(nspaceSyntax.Usings.Add(newUsing.NormalizeWhitespace()));
}
示例3: AmendUsings
private static NamespaceDeclarationSyntax AmendUsings(NamespaceDeclarationSyntax nameSpace, SyntaxList<UsingDirectiveSyntax> usings)
{
var last = nameSpace.Name.ToString().Right(c => c != '.');
foreach (var item in usings)
{
var name = item.Name.ToString();
var first = name.Left(c => c != '.');
if (first == last)
{
usings = usings.Remove(item);
usings = usings.Add(SyntaxFactory.UsingDirective(SyntaxFactory.ParseName("global::" + name)));
}
}
return nameSpace.WithUsings(usings);
}