From 039a03016419e9e9234611ba143a75400ec6325d Mon Sep 17 00:00:00 2001 From: Peter Collins Date: Tue, 12 Jul 2022 21:54:14 -0400 Subject: [DocumentationEnumerator] Support global alias matching (#641) The tooling is currently unable to match existing documentation with a member that was updated to include a global alias. Fix this by adding a a type lookup attempt that prefixes `global::` to the documentation member name. --- mdoc/Mono.Documentation/Updater/DocumentationEnumerator.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/mdoc/Mono.Documentation/Updater/DocumentationEnumerator.cs b/mdoc/Mono.Documentation/Updater/DocumentationEnumerator.cs index 3b710a98..abe87e2c 100644 --- a/mdoc/Mono.Documentation/Updater/DocumentationEnumerator.cs +++ b/mdoc/Mono.Documentation/Updater/DocumentationEnumerator.cs @@ -256,8 +256,8 @@ namespace Mono.Documentation.Updater // 1. "Normal" (non-generic) member names: GetEnumerator // - Lookup as-is. // 2. Explicitly-implemented interface member names: System.Collections.IEnumerable.Current - // - try as-is, and try type.member (due to "kludge" for property - // support. + // - try as-is, try global::namespace.type.member, and try + // type.member (due to "kludge" for property support. // 3. "Normal" Generic member names: Sort (CSC) // - need to remove generic parameters --> "Sort" // 4. Explicitly-implemented interface members for generic interfaces: @@ -294,6 +294,13 @@ namespace Mono.Documentation.Updater }; + // An explicitly-implemented interface member may have been updated to use a global alias. + foreach (MemberReference mi in type.GetMembers ($"global::{docName}")) + { + memberCount++; + yield return mi; + } + // might be a property; try only type.member instead of // namespace.type.member. var typeMember = DocUtils.GetTypeDotMember (docName); -- cgit v1.2.3 From 182299000aac99a65916ad62c82770833f03fc54 Mon Sep 17 00:00:00 2001 From: Peter Collins Date: Thu, 14 Jul 2022 09:13:01 -0400 Subject: [MDocUpdater] Fix assembly info duplication (#638) The `AssemblyPublicKey` and `AssemblyCulture` elements will be added to to a docs `index.xml` file every time the tool runs, even if the element already exists. Fix this by using `MDocUpdater.WriteElement` to write these elements, as it will first check for an existing element rather than always creating a new one. --- mdoc/Mono.Documentation/MDocUpdater.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mdoc/Mono.Documentation/MDocUpdater.cs b/mdoc/Mono.Documentation/MDocUpdater.cs index 8b858edd..269e36ea 100644 --- a/mdoc/Mono.Documentation/MDocUpdater.cs +++ b/mdoc/Mono.Documentation/MDocUpdater.cs @@ -988,7 +988,7 @@ namespace Mono.Documentation AssemblyNameDefinition name = assembly.Name; if (name.HasPublicKey) { - XmlElement pubkey = parent.OwnerDocument.CreateElement ("AssemblyPublicKey"); + XmlElement pubkey = WriteElement (index_assembly, "AssemblyPublicKey"); var key = new StringBuilder (name.PublicKey.Length * 3 + 2); key.Append ("["); foreach (byte b in name.PublicKey) @@ -1000,7 +1000,7 @@ namespace Mono.Documentation if (!string.IsNullOrEmpty (name.Culture)) { - XmlElement culture = parent.OwnerDocument.CreateElement ("AssemblyCulture"); + XmlElement culture = WriteElement (index_assembly, "AssemblyCulture"); culture.InnerText = name.Culture; index_assembly.AppendChild (culture); } -- cgit v1.2.3 From f8142884fd570204aa89fa621541809890891065 Mon Sep 17 00:00:00 2001 From: Peter Collins Date: Thu, 14 Jul 2022 22:33:45 -0400 Subject: [mdoc] Convert to SDK style projects (#642) Converts `mdoc.csproj` and `Monodoc.Test.csproj` files to SDK style projects to allow them to be built with dotnet build. --- .../CppFormatters/CppWinRtFullMemberFormatter.cs | 1 - mdoc/Mono.Documentation/Updater/XmlSyncer.cs | 269 --------------------- mdoc/mdoc.csproj | 155 ++---------- monodoc/Test/Monodoc.Test.csproj | 54 +---- 4 files changed, 22 insertions(+), 457 deletions(-) delete mode 100644 mdoc/Mono.Documentation/Updater/XmlSyncer.cs diff --git a/mdoc/Mono.Documentation/Updater/Formatters/CppFormatters/CppWinRtFullMemberFormatter.cs b/mdoc/Mono.Documentation/Updater/Formatters/CppFormatters/CppWinRtFullMemberFormatter.cs index 976d1b64..39fc085b 100644 --- a/mdoc/Mono.Documentation/Updater/Formatters/CppFormatters/CppWinRtFullMemberFormatter.cs +++ b/mdoc/Mono.Documentation/Updater/Formatters/CppFormatters/CppWinRtFullMemberFormatter.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Runtime.Remoting.Contexts; using System.Text; using Mono.Cecil; diff --git a/mdoc/Mono.Documentation/Updater/XmlSyncer.cs b/mdoc/Mono.Documentation/Updater/XmlSyncer.cs deleted file mode 100644 index dda4cd0e..00000000 --- a/mdoc/Mono.Documentation/Updater/XmlSyncer.cs +++ /dev/null @@ -1,269 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Xml; -using Mono.Cecil; -using Mono.Documentation.Updater.Frameworks; - -namespace Mono.Documentation.Updater -{ - public static class XmlSyncer - { - public static void MakeParameters (XmlElement root, MemberReference member, IList parameters, FrameworkTypeEntry typeEntry, ref bool fxAlternateTriggered) - { - XmlElement e = DocUtils.WriteElement (root, "Parameters"); - - /// addParameter does the work of adding the actual parameter to the XML - Action addParameter = (ParameterDefinition param, XmlElement nextTo, string paramType, int index, bool addIndex, string fx, bool addfx) => - { - var pe = root.OwnerDocument.CreateElement ("Parameter"); - - if (nextTo == null) - e.AppendChild (pe); - else - e.InsertAfter (pe, nextTo); - - pe.SetAttribute ("Name", param.Name); - pe.SetAttribute ("Type", paramType); - if (param.ParameterType is ByReferenceType) - { - if (param.IsOut) - pe.SetAttribute ("RefType", "out"); - else - pe.SetAttribute ("RefType", "ref"); - } - if (addIndex) - pe.SetAttribute ("Index", index.ToString ()); - if (addfx) - pe.SetAttribute (Consts.FrameworkAlternate, fx); - - MakeAttributes (pe, GetCustomAttributes (param.CustomAttributes, "")); - }; - - /// addFXAttributes, adds the index attribute to all existing elements. - /// Used when we first detect the scenario which requires this. - Action addFXAttributes = nodes => - { - var i = 0; - foreach (var node in nodes.Cast ()) - { - node.SetAttribute ("Index", i.ToString ()); - i++; - } - }; - - int parameterIndex = 0; - int parameterIndexOffset = 0; - - var paramNodes = e.GetElementsByTagName ("Parameter"); - bool inFXMode = frameworksCache.Frameworks.Count () > 1; - - foreach (ParameterDefinition p in parameters) - { - var ptype = GetDocParameterType (p.ParameterType); - if (parameterIndex >= paramNodes.Count) - { - // this parameter hasn't been added yet - bool hasParameterName = string.IsNullOrWhiteSpace (p.Name); - addParameter (p, null, ptype, parameterIndex, false, "", false); - } - else // there's enough nodes, see if it truly exists - { - //look for < parameter > that matches position - XmlElement parameterNode = e.ChildNodes[parameterIndex + parameterIndexOffset] as XmlElement; - - - if (parameterNode != null) - { - //Assert Type Matches (if not, throw?) - if (parameterNode.HasAttribute ("Name") && parameterNode.Attributes["Name"].Value == p.Name) - { - // we're good, continue on. - } - else - { // name doesn't match - if (parameterNode.HasAttribute ("Index")) - { - // TODO: add a FrameworkAlternate check, and set offset correctly - int pindex; - if (int.TryParse (parameterNode.GetAttribute ("Index"), out pindex) && pindex < parameterIndex) - { - parameterIndexOffset++; - - continue; - } - } - else - { - if (!inFXMode) throw new Exception ("shit"); - addFXAttributes (paramNodes); - //-find type in previous frameworks - - - string fxList = FXUtils.PreviouslyProcessedFXString (typeEntry); - - //-find < parameter where index = currentIndex > - var currentNode = paramNodes[parameterIndex] as XmlElement; - currentNode.SetAttribute (Consts.FrameworkAlternate, fxList); - - addParameter (p, parameterNode, ptype, parameterIndex - parameterIndexOffset, true, typeEntry.Framework.Name, true); - parameterIndexOffset++; - fxAlternateTriggered = true; - } - } - - } - else - { // no element at this index - // TODO: does this ever happen? - throw new Exception ("This wasn't supposed to happen"); - //addParameter (p); - } - /* - - If found - - Assert Type Matches (if not, throw?) - -If Name Matches … - - if “FrameworkAlternate” - -Add typeEntry.Framework.Name to list - - done! - -Else (exists, but name doesn’t match … FrameworkAlternate path) - - check if inFXMode if not, throw - -AddFXParameters - - adds Index to all existing - -Add FrameworkAlternate = allPreviousFrameworks and Index = currentIndex - - Add new node with Index = currentIndex - - else not found - -add - */ - } - parameterIndex++; - } - //-purge `typeEntry.Framework` from any that - // has FrameworkAlternate, and “name” doesn’t match any - // `parameters` - var alternates = paramNodes - .Cast () - .Select (p => new - { - Element = p, - Name = p.GetAttribute ("Name"), - FrameworkAlternate = p.GetAttribute (Consts.FrameworkAlternate) - }) - .Where (p => - !string.IsNullOrWhiteSpace (p.FrameworkAlternate) && - p.FrameworkAlternate.Contains (typeEntry.Framework.Name) && - !parameters.Any (param => param.Name == p.Name)) - .ToArray (); - if (alternates.Any ()) - { - foreach (var a in alternates) - { - string newValue = FXUtils.RemoveFXFromList (a.FrameworkAlternate, typeEntry.Framework.Name); - if (string.IsNullOrWhiteSpace (newValue)) - { - a.Element.RemoveAttribute (Consts.FrameworkAlternate); - } - else - { - a.Element.SetAttribute (Consts.FrameworkAlternate, newValue); - } - } - } - - return; - /* - // old code - foreach (ParameterDefinition p in parameters) - { - XmlElement pe; - - // param info - var ptype = GetDocParameterType (p.ParameterType); - var newPType = ptype; - - if (MDocUpdater.SwitchingToMagicTypes) - { - newPType = NativeTypeManager.ConvertFromNativeType (ptype); - } - - // now find the existing node, if it's there so we can reuse it. - var nodes = root.SelectSingleNode ("Parameters").SelectNodes ("Parameter") - .Cast ().Where (x => x.GetAttribute ("Name") == p.Name) - .ToArray (); - - // FYI: Exists? No? - if (nodes.Count () == 0) - { - // TODO: instead of this. Needs to be replaced with a better - // check for Parameter index ... should I add parameter index? - - // are we in frameworks mode? - // add Index to all existing parameter nodes if they don't have them - // match existing to position and type - bool _inFXMode = typeEntry.Framework.Frameworks.Count () > 1; - - // when I find the one, name won't match ... - - // find all "previous" frameworks - // Add FrameworkAlternate with previous frameworks to found/pre-existing node - var allPreviousTypes_ = typeEntry.Framework.Frameworks - .Where (f => f.index < typeEntry.Framework.index) - .Select (f => f.FindTypeEntry (typeEntry)) - .ToArray (); - - var allPreviousFrameworks = allPreviousTypes.Value.Select (previous => previous.Framework.Name).ToArray (); - string fxList = string.Join (";", allPreviousFrameworks); - - // find the parameters in `root` that have an index == this parameter's index - // if they don't match, then we need to make a new one for this - - // Create new "Parameter" node, with FrameworkAlternate = this - - // Legacy: wasn't found, let's make sure it wasn't just cause the param name was changed - nodes = root.SelectSingleNode ("Parameters").SelectNodes ("Parameter") - .Cast () - .Skip (parameterIndex) // this makes sure we don't inadvertently "reuse" nodes when adding new ones - .Where (x => x.GetAttribute ("Name") != p.Name && (x.GetAttribute ("Type") == ptype || x.GetAttribute ("Type") == newPType)) - .Take (1) // there might be more than one that meets this parameter ... only take the first. - .ToArray (); - } - - AddXmlNode (nodes, - x => x.GetAttribute ("Type") == ptype, - x => x.SetAttribute ("Type", ptype), - () => - { - pe = root.OwnerDocument.CreateElement ("Parameter"); - e.AppendChild (pe); - - pe.SetAttribute ("Name", p.Name); - pe.SetAttribute ("Type", ptype); - if (p.ParameterType is ByReferenceType) - { - if (p.IsOut) - pe.SetAttribute ("RefType", "out"); - else - pe.SetAttribute ("RefType", "ref"); - } - - MakeAttributes (pe, GetCustomAttributes (p.CustomAttributes, "")); - return pe; - }, - member); - - parameterIndex++; - } - - // TODO: was there a `Parameter` that we didn't process that has FrameworkAlternate? - // if yes, remove this framework from that FrameworkAlternate - // if that makes the list empty, remove the node and corresponding /Docs/parameter node - */ - } - - - - - } -} diff --git a/mdoc/mdoc.csproj b/mdoc/mdoc.csproj index e87db9c6..f0051cc0 100644 --- a/mdoc/mdoc.csproj +++ b/mdoc/mdoc.csproj @@ -1,144 +1,20 @@  - + - Debug - AnyCPU - 8.0.30703 - 2.0 - {7DA7CD97-614F-4BCD-A2FA-B379590CEA48} + net471 Exe - mdoc - mdoc - v4.7.1 + false + false + $(MSBuildThisFileDirectory)..\bin\$(Configuration) - - True - full - False - ..\bin\Debug - DEBUG;NET_4_5 - prompt - 4 - AnyCPU - True - false - - - none - true - ..\bin\Release - prompt - 4 - AnyCPU - True - false - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + defaulttemplate.xsl @@ -156,6 +32,7 @@ stylesheet.xsl + Resources\mdoc-html-format.xsl @@ -170,16 +47,14 @@ Resources\mono-ecma-css.xsl + + - - {6e644802-b579-4037-9809-9cf4c7172c9d} - monodoc - + - diff --git a/monodoc/Test/Monodoc.Test.csproj b/monodoc/Test/Monodoc.Test.csproj index 37d9b576..e721e11c 100644 --- a/monodoc/Test/Monodoc.Test.csproj +++ b/monodoc/Test/Monodoc.Test.csproj @@ -1,59 +1,19 @@  - + - Debug - AnyCPU - 8.0.30703 - 2.0 - {1EE70E2C-A289-4C36-AD0A-3D0C6CE56615} - Library - Monodoc.Test - Monodoc.Test - v4.7.1 - - - + net471 + false - - true - full - false - bin\Debug - DEBUG; - prompt - 4 - - - true - bin\Release - prompt - 4 - - - - - + + - - - - - - - - - - - - {6e644802-b579-4037-9809-9cf4c7172c9d} - monodoc - + + - \ No newline at end of file -- cgit v1.2.3 From 461da7b8188ad1d217f82ceb4c23df049ca2f466 Mon Sep 17 00:00:00 2001 From: huangmin-ms Date: Fri, 15 Jul 2022 14:14:24 +0800 Subject: bump mdoc to 5.8.9.2 --- mdoc/Consts.cs | 2 +- mdoc/mdoc.nuspec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mdoc/Consts.cs b/mdoc/Consts.cs index e0b10fce..7d64b319 100644 --- a/mdoc/Consts.cs +++ b/mdoc/Consts.cs @@ -3,7 +3,7 @@ namespace Mono.Documentation { public static class Consts { - public static string MonoVersion = "5.8.9.1"; + public static string MonoVersion = "5.8.9.2"; public const string DocId = "DocId"; public const string CppCli = "C++ CLI"; public const string CppCx = "C++ CX"; diff --git a/mdoc/mdoc.nuspec b/mdoc/mdoc.nuspec index b73cc40d..a491afc9 100644 --- a/mdoc/mdoc.nuspec +++ b/mdoc/mdoc.nuspec @@ -2,7 +2,7 @@ mdoc - 5.8.9.1 + 5.8.9.2 mdoc Microsoft Microsoft -- cgit v1.2.3