/// <summary> /// Ensures if the declaration has more than 1 accessor that they are in the correct order. /// </summary> /// <param name="declarationNode"> /// The node to use. /// </param> public static void CheckAccessorOrder(IAccessorOwnerDeclarationNode declarationNode) { IList <IAccessorDeclaration> accessorDeclarations = declarationNode.AccessorDeclarations; if (accessorDeclarations.Count < 2) { // don't need to reorder because there's only 1 (or none) return; } // we now know we have 2 accessors IAccessorDeclaration firstAccessor = accessorDeclarations[0]; IAccessorDeclaration secondAccessor = accessorDeclarations[1]; if (firstAccessor.Kind == AccessorKind.GETTER || firstAccessor.Kind == AccessorKind.ADDER) { return; } IAccessorDeclaration newAccessor = firstAccessor.CopyElementWithResolve(); declarationNode.AddAccessorDeclarationAfter(newAccessor, secondAccessor); declarationNode.RemoveAccessorDeclaration(firstAccessor); LayoutRules.ClosingCurlyBracketMustBeFollowedByBlankLine(declarationNode); }
/// <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) { IElement element = Utils.GetElementAtCaret(solution, textControl); IAccessorOwnerDeclarationNode declaration = element.GetContainingElement <IAccessorOwnerDeclarationNode>(true); if (declaration != null) { OrderingRules.CheckAccessorOrder(declaration); } }