/// <summary> /// The execute transaction inner. /// </summary> /// <param name="solution"> /// The solution. /// </param> /// <param name="textControl"> /// The text control. /// </param> public override void ExecuteTransactionInner(ISolution solution, ITextControl textControl) { ITreeNode element = Utils.GetElementAtCaret(solution, textControl); if (element == null) { return; } IUsingList usingList = element.GetContainingNode(typeof(IUsingList), false) as IUsingList; if (usingList == null) { return; } ICSharpFile file = Utils.GetCSharpFile(solution, textControl); // This violation will only run if there are some using statements and definately at least 1 namespace // so [0] index will always be OK. ICSharpNamespaceDeclaration firstNamespace = file.NamespaceDeclarations[0]; foreach (IUsingDirective usingDirectiveNode in usingList.Imports) { firstNamespace.AddImportBefore(usingDirectiveNode, null); file.RemoveImport(usingDirectiveNode); } // Now sort the Usings into order. OrderUsingsBulbItem orderUsingsBulbItem = new OrderUsingsBulbItem(); orderUsingsBulbItem.ExecuteTransactionInner(solution, textControl); }
private static IEnumerable <ITypeDeclaration> GetDeclarationsFromCSharpNamespace(ICSharpNamespaceDeclaration namespaceDeclaration) { foreach (var namespaceChild in namespaceDeclaration.Body.Children()) { var classDeclaration = namespaceChild as IClassDeclaration; if (classDeclaration != null) { yield return(classDeclaration); } else { var childNamespace = namespaceChild as ICSharpNamespaceDeclaration; if (childNamespace != null) { foreach (var declaration in GetDeclarationsFromCSharpNamespace(childNamespace)) { yield return(declaration); } } } } }
public void RemoveNamespaceDeclaration(ICSharpNamespaceDeclaration param) { _file.RemoveNamespaceDeclaration(param); }
public ICSharpNamespaceDeclaration AddNamespaceDeclarationAfter(ICSharpNamespaceDeclaration param, ICSharpNamespaceDeclaration anchor) { return(_file.AddNamespaceDeclarationAfter(param, anchor)); }
public ICSharpNamespaceDeclaration AddNamespaceDeclarationBefore(ICSharpNamespaceDeclaration param, ICSharpNamespaceDeclaration anchor) { return _file.AddNamespaceDeclarationBefore(param, anchor); }