Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion mcs/class/monodoc/Monodoc.Ecma/EcmaDesc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,9 @@ void ConstructCRef (StringBuilder sb)

sb.Append ('.');
sb.Append (TypeName);
if (GenericTypeArguments != null) {
if (GenericTypeArguments != null && GenericTypeArgumentsIsNumeric) {
sb.AppendFormat ("`{0}", GenericTypeArgumentsCount);
} else if (GenericTypeArguments != null) {
sb.Append ('<');
int i=0;
foreach (var t in GenericTypeArguments) {
Expand Down
4 changes: 4 additions & 0 deletions mcs/class/monodoc/Resources/mdoc-html-utils.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,10 @@
<xsl:with-param name="child-id" select="concat ($linkid, ':Related:')" />
<xsl:with-param name="content">
<div class="related">
<xsl:call-template name="CreateRelatedSection">
<xsl:with-param name="section" select="'Platform Docs'" />
<xsl:with-param name="type" select="'PlatformDocAPI'" />
</xsl:call-template>
<xsl:call-template name="CreateRelatedSection">
<xsl:with-param name="section" select="'Articles'" />
<xsl:with-param name="type" select="'article'" />
Expand Down
11 changes: 11 additions & 0 deletions mcs/class/monodoc/Test/Monodoc.Ecma/EcmaUrlTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,17 @@ public void GenericTypeArgsIsNumericTest ()
Assert.IsFalse (desc.GenericTypeArgumentsIsNumeric);
}

[Test]
public void GenericTypeArgsNumericToStringTest ()
{
string stringCref = "T:System.Collections.Generic.Dictionary`2";
var desc = parser.Parse (stringCref);
Assert.IsTrue (desc.GenericTypeArgumentsIsNumeric);
Assert.AreEqual (2, desc.GenericTypeArguments.Count);
string generatedEcmaCref = desc.ToEcmaCref ();
Assert.AreEqual (stringCref, generatedEcmaCref);
}

[Test]
public void MetaEtcNodeTest ()
{
Expand Down
21 changes: 21 additions & 0 deletions mcs/tools/mdoc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ cleanup:
-rm -Rf Test/en.actual Test/html.actual
-rm -f monodocer1.exe*

Test/DocTest-addNonGeneric.dll:
$(CSCOMPILE) $(TEST_CSCFLAGS) -debug -unsafe -target:library -out:$@ Test/DocTest-addNonGeneric.cs

Test/DocTest-addNonGeneric-v2.dll:
$(CSCOMPILE) $(TEST_CSCFLAGS) -debug -unsafe -target:library -out:$@ Test/DocTest-addNonGeneric.cs /define:V2

Test/DocTest-DropNS-classic-secondary.dll:
@echo $(value @)
$(CSCOMPILE) $(TEST_CSCFLAGS) -debug -unsafe -target:library -out:$@ Test/DocTest-DropNS-classic-secondary.cs
Expand Down Expand Up @@ -121,6 +127,19 @@ Test/DocTest.dll-v2:
-rm -f Test/DocTest.dll
$(MAKE) TEST_CSCFLAGS=$(TEST_CSCFLAGS) Test/DocTest.dll

check-monodocer-addNonGeneric: $(PROGRAM)
-rm -Rf Test/en.actual
# first, make a docset with the generic method
$(MAKE) Test/DocTest-addNonGeneric.dll
$(MONO) $(PROGRAM) update --exceptions=all -o Test/en.actual Test/DocTest-addNonGeneric.dll

# now add a non-generic version of the method and update several times
$(MAKE) Test/DocTest-addNonGeneric-v2.dll
$(MONO) $(PROGRAM) update --exceptions=all -o Test/en.actual Test/DocTest-addNonGeneric-v2.dll
$(MONO) $(PROGRAM) update --exceptions=all -o Test/en.actual Test/DocTest-addNonGeneric-v2.dll
$(MONO) $(PROGRAM) update --exceptions=all -o Test/en.actual Test/DocTest-addNonGeneric-v2.dll
diff --exclude=.svn -rup Test/en.expected-addNonGeneric Test/en.actual

check-monodocer-dropns-classic: $(PROGRAM)
# tests the simplest --dropns case, a single class where the root namespace was dropped.
-rm -Rf Test/en.actual
Expand Down Expand Up @@ -321,4 +340,6 @@ check-doc-tools-update: check-monodocer-since-update \
check-mdoc-export-msxdoc-update \
check-mdoc-validate-update

check: check-doc-tools \
check-doc-tools-update

47 changes: 42 additions & 5 deletions mcs/tools/mdoc/Mono.Documentation/monodocer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3230,16 +3230,21 @@ protected static MemberReference GetMember (TypeDefinition type, DocumentationMe
if (mi is MethodDefinition) {
MethodDefinition mb = (MethodDefinition) mi;
pis = mb.Parameters;
if (docTypeParams != null && mb.IsGenericMethod ()) {
if (mb.IsGenericMethod ()) {
IList<GenericParameter> args = mb.GenericParameters;
if (args.Count == docTypeParams.Length) {
typeParams = args.Select (p => p.Name).ToArray ();
}
typeParams = args.Select (p => p.Name).ToArray ();
}
}
else if (mi is PropertyDefinition)
pis = ((PropertyDefinition)mi).Parameters;


// check type parameters
int methodTcount = member.TypeParameters == null ? 0 : member.TypeParameters.Count;
int reflectionTcount = typeParams == null ? 0 : typeParams.Length;
if (methodTcount != reflectionTcount)
continue;

// check member parameters
int mcount = member.Parameters == null ? 0 : member.Parameters.Count;
int pcount = pis == null ? 0 : pis.Count;
if (mcount != pcount)
Expand Down Expand Up @@ -3793,6 +3798,7 @@ class DocumentationMember {
public StringToStringMap MemberSignatures = new StringToStringMap ();
public string ReturnType;
public StringList Parameters;
public StringList TypeParameters;
public string MemberName;
public string MemberType;

Expand All @@ -3802,6 +3808,7 @@ public DocumentationMember (XmlReader reader)
int depth = reader.Depth;
bool go = true;
StringList p = new StringList ();
StringList tp = new StringList ();
do {
if (reader.NodeType != XmlNodeType.Element)
continue;
Expand Down Expand Up @@ -3829,6 +3836,10 @@ public DocumentationMember (XmlReader reader)
if (reader.Depth == depth + 2 && shouldUse)
p.Add (reader.GetAttribute ("Type"));
break;
case "TypeParameter":
if (reader.Depth == depth + 2 && shouldUse)
tp.Add (reader.GetAttribute ("Name"));
break;
case "Docs":
if (reader.Depth == depth + 1)
go = false;
Expand All @@ -3838,6 +3849,11 @@ public DocumentationMember (XmlReader reader)
if (p.Count > 0) {
Parameters = p;
}
if (tp.Count > 0) {
TypeParameters = tp;
} else {
DiscernTypeParameters ();
}
}

public DocumentationMember (XmlNode node)
Expand All @@ -3861,6 +3877,27 @@ public DocumentationMember (XmlNode node)
for (int i = 0; i < p.Count; ++i)
Parameters.Add (p [i].Attributes ["Type"].Value);
}
XmlNodeList tp = node.SelectNodes ("TypeParameters/TypeParameter[not(@apistyle) or @apistyle='classic']");
if (tp.Count > 0) {
TypeParameters = new StringList (tp.Count);
for (int i = 0; i < tp.Count; ++i)
TypeParameters.Add (tp [i].Attributes ["Name"].Value);
}
else {
DiscernTypeParameters ();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would probably be a good "sanity check" to always call DiscernTypeParameters() (-ish...), and if TypeParameters already has elements, ensure that the "discerned" count matches the "real" count, because if they don't match, something has gone horribly, horribly, wrong.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, this won't always be the case, particularly for importing docs generated from triple-slash ... for example:
https://github.com/mono/mono/blob/master/mcs/tools/mdoc/Test/TestEcmaDocs.xml#L317

The docs there don't have a TypeParameter list, so I went with the approach of checking for TypeParameters, and otherwise falling back to checking for type parameters in the name string.

}
}

void DiscernTypeParameters ()
{
// see if we can discern the param list from the name
if (MemberName.Contains ("<") && MemberName.EndsWith (">")) {
var starti = MemberName.IndexOf ("<") + 1;
var endi = MemberName.LastIndexOf (">");
var paramlist = MemberName.Substring (starti, endi - starti);
var tparams = paramlist.Split (new char[] {','}, StringSplitOptions.RemoveEmptyEntries);
TypeParameters = new StringList (tparams);
}
}
}

Expand Down
9 changes: 9 additions & 0 deletions mcs/tools/mdoc/Test/DocTest-addNonGeneric.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace MyNamespace {
public class MyClass {
public string SomeMethod<T>() { return string.Empty; }

#if V2
public string SomeMethod() { return string.Empty; }
#endif
}
}
5 changes: 3 additions & 2 deletions mcs/tools/mdoc/mdoc.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
<OutputType>Exe</OutputType>
<RootNamespace>mdoc</RootNamespace>
<AssemblyName>mdoc</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<DebugSymbols>True</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>False</Optimize>
<OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG;NET_4_0</DefineConstants>
<DefineConstants>DEBUG;NET_4_5</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x86</PlatformTarget>
Expand All @@ -38,7 +39,7 @@
<Reference Include="System.Xml" />
<Reference Include="Mono.Cecil, Version=0.9.5.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756" />
<Reference Include="monodoc">
<HintPath>..\..\class\lib\net_4_0\monodoc.dll</HintPath>
<HintPath>..\..\class\lib\net_4_5\monodoc.dll</HintPath>
</Reference>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
Expand Down