private static UsingDirectiveSyntax[] GenerateUsings(SyntaxNode root, ClassDeclarationSyntax context) { List <string> compositeNamespace = new List <string>(); SyntaxNode node = context.Parent; while (node.GetType() != typeof(NamespaceDeclarationSyntax)) { compositeNamespace.Add((node as ClassDeclarationSyntax)?.Identifier.ValueText); node = node.Parent; } compositeNamespace.Add((node as NamespaceDeclarationSyntax).Name.ToString()); compositeNamespace.Reverse(); UsingDirectiveSyntax space = SyntaxFactory.UsingDirective(SyntaxFactory.ParseName(string.Join('.', compositeNamespace.ToArray()))); if (compositeNamespace.Count > 1) { space = space.WithStaticKeyword(staticKeyword); } return(root.DescendantNodes().OfType <UsingDirectiveSyntax>(). Prepend(space). Append(SyntaxFactory.UsingDirective(SyntaxFactory.ParseName("NUnit.Framework"))). Append(SyntaxFactory.UsingDirective(SyntaxFactory.ParseName("Moq"))). ToArray()); }
/// <summary> /// Makes using directive static /// </summary> /// <param name="uds">Using directive</param> /// <returns>Fluent</returns> public static UsingDirectiveSyntax Static(this UsingDirectiveSyntax uds) { return(uds.WithStaticKeyword( Token( TriviaList(), SyntaxKind.StaticKeyword, TriviaList( Space)))); }