private static Task <Document> OrderElementsAsync(
            Document document,
            XmlElementSyntax xmlElement,
            CancellationToken cancellationToken)
        {
            var documentationComment = (DocumentationCommentTriviaSyntax)xmlElement.Parent;

            SyntaxList <XmlNodeSyntax> content = documentationComment.Content;

            MemberDeclarationSyntax memberDeclaration = xmlElement.FirstAncestor <MemberDeclarationSyntax>();

            int firstIndex = content.IndexOf(xmlElement);

            SyntaxList <XmlNodeSyntax> newContent = GetNewContent();

            DocumentationCommentTriviaSyntax newDocumentationComment = documentationComment.WithContent(newContent);

            return(document.ReplaceNodeAsync(documentationComment, newDocumentationComment, cancellationToken));

            SyntaxList <XmlNodeSyntax> GetNewContent()
            {
                switch (SyntaxInfo.XmlElementInfo(xmlElement).GetElementKind())
                {
                case XmlElementKind.Param:
                {
                    SeparatedSyntaxList <ParameterSyntax> parameters = ParameterListInfo.Create(memberDeclaration).Parameters;

                    return(SortElements(parameters, content, firstIndex, XmlElementKind.Param, (nodes, name) => nodes.IndexOf(name)));
                }

                case XmlElementKind.TypeParam:
                {
                    SeparatedSyntaxList <TypeParameterSyntax> typeParameters = TypeParameterListInfo.Create(memberDeclaration).Parameters;

                    return(SortElements(typeParameters, content, firstIndex, XmlElementKind.TypeParam, (nodes, name) => nodes.IndexOf(name)));
                }

                default:
                {
                    throw new InvalidOperationException();
                }
                }
            }
        }