/// <summary> /// Move <paramref name="toMove"></paramref> before <paramref name="member">.</paramref>. /// </summary> /// <param name="editor">The <see cref="DocumentEditor"/>.</param> /// <param name="toMove">The <see cref="MemberDeclarationSyntax"/> to move.</param> /// <param name="member">The <see cref="MemberDeclarationSyntax"/>.</param> /// <returns>The <see cref="DocumentEditor"/> that was passed in.</returns> public static DocumentEditor MoveAfter(this DocumentEditor editor, MemberDeclarationSyntax toMove, MemberDeclarationSyntax member) { if (editor is null) { throw new ArgumentNullException(nameof(editor)); } if (toMove is null) { throw new ArgumentNullException(nameof(toMove)); } if (member is null) { throw new ArgumentNullException(nameof(member)); } editor.RemoveNode(toMove); editor.InsertAfter(member, ToMove()); editor.ReplaceNode(member, Member()); return(editor); MemberDeclarationSyntax ToMove() { return(toMove.AdjustLeadingNewLine(member)); } MemberDeclarationSyntax Member() { if (member.Parent is TypeDeclarationSyntax typeDeclaration) { var index = typeDeclaration.Members.IndexOf(member) - 1; if (typeDeclaration.Members.IndexOf(toMove) == index) { index--; } return(member.AdjustLeadingNewLine(typeDeclaration.Members.ElementAtOrDefault(index))); } return(toMove); } }