public static CompilationUnitSyntax AddUsingDirective( this CompilationUnitSyntax root, UsingDirectiveSyntax usingDirective, SyntaxNode contextNode, bool placeSystemNamespaceFirst, params SyntaxAnnotation[] annotations) { return root.AddUsingDirectives(new[] { usingDirective }, contextNode, placeSystemNamespaceFirst, annotations); }
public static CompilationUnitSyntax AddUsingDirectives( this CompilationUnitSyntax root, IList<UsingDirectiveSyntax> usingDirectives, SyntaxNode contextNode, bool placeSystemNamespaceFirst, params SyntaxAnnotation[] annotations) { if (!usingDirectives.Any()) { return root; } var firstOuterNamespaceWithUsings = contextNode.GetInnermostNamespaceDeclarationWithUsings(); if (firstOuterNamespaceWithUsings == null) { return root.AddUsingDirectives(usingDirectives, placeSystemNamespaceFirst, annotations); } else { var newNamespace = firstOuterNamespaceWithUsings.AddUsingDirectives(usingDirectives, placeSystemNamespaceFirst, annotations); return root.ReplaceNode(firstOuterNamespaceWithUsings, newNamespace); } }