diff --git a/mdoc/Mono.Documentation/MDocUpdater.cs b/mdoc/Mono.Documentation/MDocUpdater.cs index fc4dc3bb0..f1a227597 100644 --- a/mdoc/Mono.Documentation/MDocUpdater.cs +++ b/mdoc/Mono.Documentation/MDocUpdater.cs @@ -2476,8 +2476,17 @@ private static void UpdateSignature(MemberFormatter formatter, TypeDefinition ty return; // if first framework of type, clear signatures and generate from scratch + // try to keep order if there's only one existing element + XmlNode previousSiblingOfExistingElement = null; + XmlNode nextSiblingOfExistingElement = null; if (typeEntry.Framework.IsFirstFrameworkForType(typeEntry)) { + if (existingElements.Count() == 1) + { + var firstExistingElement = existingElements.First(); + previousSiblingOfExistingElement = firstExistingElement.PreviousSibling; + nextSiblingOfExistingElement = firstExistingElement.NextSibling; + } existingElements.ForEach(e => e.ParentNode.RemoveChild(e)); existingElements = QueryXmlElementsByXpath(xmlElement, elementXPath).ToList(); } @@ -2510,7 +2519,18 @@ private static void UpdateSignature(MemberFormatter formatter, TypeDefinition ty if (!elementFound) //not exists, add signature with fxa { var newElement = xmlElement.OwnerDocument.CreateElement(elementName); - xmlElement.AppendChild(newElement); + if (previousSiblingOfExistingElement != null) + { + xmlElement.InsertAfter(newElement, previousSiblingOfExistingElement); + } + else if (nextSiblingOfExistingElement != null) + { + xmlElement.InsertBefore(newElement, nextSiblingOfExistingElement); + } + else + { + xmlElement.AppendChild(newElement); + } newElement.SetAttribute("Language", formatter.Language); if (!string.IsNullOrWhiteSpace(valueToUse)) @@ -2578,8 +2598,16 @@ public static void UpdateSignature(MemberFormatter formatter, MemberReference me return; // pre: clear all the signatures + XmlNode previousSiblingOfExistingElement = null; + XmlNode nextSiblingOfExistingElement = null; if (typeEntry.IsMemberOnFirstFramework(member)) { + if (existingElements.Count() == 1) + { + var firstExistingElement = existingElements.First(); + previousSiblingOfExistingElement = firstExistingElement.PreviousSibling; + nextSiblingOfExistingElement = firstExistingElement.NextSibling; + } foreach (var element in existingElements)// xmlElement.SelectNodes(elementName).SafeCast()) { // remove element @@ -2620,7 +2648,18 @@ public static void UpdateSignature(MemberFormatter formatter, MemberReference me if (!elementFound) //not exists, just add it with fxa { var newElement = xmlElement.OwnerDocument.CreateElement(elementName); - xmlElement.AppendChild(newElement); + if (previousSiblingOfExistingElement != null) + { + xmlElement.InsertAfter(newElement, previousSiblingOfExistingElement); + } + else if (nextSiblingOfExistingElement != null) + { + xmlElement.InsertBefore(newElement, nextSiblingOfExistingElement); + } + else + { + xmlElement.AppendChild(newElement); + } newElement.SetAttribute("Language", formatter.Language); if (!string.IsNullOrWhiteSpace(valueToUse)) diff --git a/mdoc/Test/en.expected-eii-implementation-ecmadoc/CustomNamespace/ClassEnumerator.xml b/mdoc/Test/en.expected-eii-implementation-ecmadoc/CustomNamespace/ClassEnumerator.xml index 2cee22469..b70047dd1 100644 --- a/mdoc/Test/en.expected-eii-implementation-ecmadoc/CustomNamespace/ClassEnumerator.xml +++ b/mdoc/Test/en.expected-eii-implementation-ecmadoc/CustomNamespace/ClassEnumerator.xml @@ -26,12 +26,12 @@ - - - + + + Constructor 0.0.65535.65535 @@ -44,11 +44,11 @@ - - - + + + Property @@ -65,11 +65,11 @@ - - - + + + Property @@ -86,13 +86,13 @@ - - - - + + + + Method 0.0.65535.65535