Skip to content

Commit 8b9792c

Browse files
committed
When importing doc from comment xml, we should clean up existing
1 parent 6fad2bf commit 8b9792c

File tree

6 files changed

+84
-11
lines changed

6 files changed

+84
-11
lines changed

mdoc/Mono.Documentation/MDocUpdater.cs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3391,17 +3391,22 @@ private void MakeDocNode (DocsNodeInfo info, IEnumerable<DocumentationImporter>
33913391
}
33923392
}
33933393
else
3394-
{
3395-
if (DocUtils.NeedsOverwrite(e["returns"]))
3396-
{
3397-
if (CheckRemoveByImporter("returns"))
3398-
ClearElement(e, "returns");
3399-
}
3400-
if (DocUtils.NeedsOverwrite(e["value"]))
3394+
{
3395+
var commMemberKeys = new string[] { "returns", "value", "related" };
3396+
for (int i = 0; i < commMemberKeys.Length; i++)
34013397
{
3402-
if (CheckRemoveByImporter("value"))
3403-
ClearElement(e, "value");
3404-
}
3398+
if (DocUtils.NeedsOverwrite(e[commMemberKeys[i]]))
3399+
if (DocUtils.CheckRemoveByImporter(info, commMemberKeys[i], importers, setimporters))
3400+
ClearElement(e, commMemberKeys[i]);
3401+
}
3402+
3403+
var altMemberKeys = new string[] { "altmember", "seealso" };
3404+
for (int i = 0; i < altMemberKeys.Length; i++)
3405+
{
3406+
if (DocUtils.NeedsOverwrite(e["altmember"]))
3407+
if (DocUtils.CheckRemoveByImporter(info, altMemberKeys[i], importers, setimporters))
3408+
ClearElement(e, "altmember");
3409+
}
34053410
}
34063411

34073412
if (addremarks)

mdoc/Mono.Documentation/Updater/DocUtils.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -891,5 +891,25 @@ public static List<GenericParameter> GetGenericParameters(TypeDefinition type)
891891
}
892892
return assemblyDelList;
893893
}
894+
895+
public static bool CheckRemoveByImporter(DocsNodeInfo info, string keyName, List<DocumentationImporter> DocImports, IEnumerable<DocumentationImporter> SetImports)
896+
{
897+
foreach (DocumentationImporter i in DocImports)
898+
{
899+
if (i.CheckRemoveByMapping(info, keyName))
900+
return true;
901+
}
902+
903+
if (SetImports != null)
904+
{
905+
foreach (var i in SetImports)
906+
{
907+
if (i.CheckRemoveByMapping(info, keyName))
908+
return true;
909+
}
910+
}
911+
912+
return false;
913+
}
894914
}
895915
}

mdoc/Mono.Documentation/Updater/MsxdocDocumentationImporter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
namespace Mono.Documentation.Updater
1010
{
11-
class MsxdocDocumentationImporter : DocumentationImporter
11+
public class MsxdocDocumentationImporter : DocumentationImporter
1212
{
1313
XmlDocument slashdocs;
1414
Dictionary<string, XmlNode> slashdocsMapping = new Dictionary<string, XmlNode>();

mdoc/mdoc.Test/MDocUpdaterTests.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Collections.Generic;
2+
using System.IO;
23
using System.Linq;
34
using System.Reflection;
45
using System.Xml;
@@ -156,5 +157,31 @@ private List<XmlElement> UpdateXml(string XmlNodeName, MemberReference mi)
156157

157158
return returnValue;
158159
}
160+
161+
[Test]
162+
public void Update_ImportDoc_Test()
163+
{
164+
List<DocumentationImporter> setimporters = new List<DocumentationImporter>();
165+
List<DocumentationImporter> importers = new List<DocumentationImporter>();
166+
var filePath = Path.Combine(Path.GetDirectoryName(this.GetType().Module.Assembly.Location), "SampleClasses\\testImportDoc.xml");
167+
MsxdocDocumentationImporter importer = new MsxdocDocumentationImporter(
168+
filePath);
169+
setimporters.Add(importer);
170+
171+
XmlDocument doc = new System.Xml.XmlDocument();
172+
doc.LoadXml(XmlConsts.internalEllXml);
173+
174+
var type = GetType(typeof(mdoc.Test2.InternalEIICalss));
175+
var docEnum = new DocumentationEnumerator();
176+
177+
var nodeMember = docEnum.GetDocumentationMembers(doc, type, FrameworkTypeEntry.Empty).FirstOrDefault(t => t.Member.FullName == "System.String mdoc.Test2.InternalEIICalss::Getstring(System.Int32)");
178+
179+
var testKeys = new string[] { "returns", "value", "related", "seealso" };
180+
181+
for (int i = 0; i < testKeys.Length; i++)
182+
{
183+
Assert.IsTrue(DocUtils.CheckRemoveByImporter(nodeMember, testKeys[i], importers, setimporters));
184+
}
185+
}
159186
}
160187
}

mdoc/mdoc.Test/SampleClasses/testImportDoc.xml

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mdoc/mdoc.Test/mdoc.Test.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@
160160
<Link>SampleClasses\cppcli.dll</Link>
161161
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
162162
</Content>
163+
<Content Include="SampleClasses\testImportDoc.xml">
164+
<Link>SampleClasses\testImportDoc.xml</Link>
165+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
166+
</Content>
163167
</ItemGroup>
164168
<ItemGroup />
165169
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />

0 commit comments

Comments
 (0)