Skip to content

Commit 30de437

Browse files
authored
Merge pull request #536 from mono/marj/mdoc-5.8.1
mdoc 5.8.1
2 parents c6411bb + c19fa34 commit 30de437

File tree

11 files changed

+141
-18
lines changed

11 files changed

+141
-18
lines changed
512 Bytes
Binary file not shown.

external/Test/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ The files in this directory are used as test inputs for explicit assembly testin
44
|---|---|
55
|CSharpExample.dll|TBD|
66
|mdoc.Test.Cplusplus.dll|../../mdoc/mdoc.Test.Cplusplus|
7-
|mdoc.Test.NullableReferenceTypes|../../mdoc/mdoc.Test/NullableReferenceTypesTests|
7+
|mdoc.Test.NullableReferenceTypes.dll|../../mdoc/mdoc.Test/NullableReferenceTypesTests|
88
|UWPTestComponentCSharp.winmd|../../mdoc/mdoc.Test/UWPTestComponentCSharp|
99
|UwpTestWinRtComponentCpp.dll|../../mdoc/mdoc.Test/UwpTestWinRtComponentCpp|
1010
|UwpTestWinRtComponentCpp.winmd|../../mdoc/mdoc.Test/UwpTestWinRtComponentCpp|

mdoc/Consts.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ namespace Mono.Documentation
33
{
44
public static class Consts
55
{
6-
public static string MonoVersion = "5.8";
6+
public static string MonoVersion = "5.8.1";
77
public const string DocId = "DocId";
88
public const string CppCli = "C++ CLI";
99
public const string CppCx = "C++ CX";

mdoc/Mono.Documentation/Updater/Formatters/CSharpFullMemberFormatter.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -430,16 +430,29 @@ protected override StringBuilder AppendMethodName (StringBuilder buf, MethodDefi
430430

431431
protected override string GetTypeNullableSymbol(TypeReference type, bool? isNullableType)
432432
{
433-
if (isNullableType.IsTrue() &&
434-
!type.IsValueType &&
435-
!type.FullName.Equals("System.Void"))
433+
if (isNullableType.IsTrue() && !IsValueTypeOrDefineByReference(type) && !type.FullName.Equals("System.Void"))
436434
{
437435
return "?";
438436
}
439437

440438
return string.Empty;
441439
}
442440

441+
private bool IsValueTypeOrDefineByReference(TypeReference type)
442+
{
443+
if (type.IsValueType)
444+
{
445+
return true;
446+
}
447+
448+
if (type is ByReferenceType byRefType)
449+
{
450+
return byRefType.ElementType.IsValueType;
451+
}
452+
453+
return false;
454+
}
455+
443456
protected override StringBuilder AppendGenericMethodConstraints (StringBuilder buf, MethodDefinition method)
444457
{
445458
if (method.GenericParameters.Count == 0)

mdoc/Mono.Documentation/Updater/Formatters/MemberFormatter.cs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -325,25 +325,18 @@ protected virtual StringBuilder AppendGenericType (StringBuilder buf, TypeRefere
325325
int argIdx = 0;
326326
int prev = 0;
327327
bool insertNested = false;
328-
var isGenericType = type is GenericInstanceType;
329-
var declaringType = isGenericType ? type.GetElementType () : type;
328+
var declaringType = type is GenericInstanceType ? type.GetElementType () : type;
330329
List<TypeReference> decls = DocUtils.GetDeclaringTypes (declaringType);
331330
List<TypeReference> genArgs = GetGenericArguments (type);
332331
foreach (var decl in decls)
333332
{
334-
TypeReference declDef = decl;
335-
if (!isGenericType)
336-
{
337-
// Generic type can't be resolve in WSL, macOS and Ubuntu OS environment that
338-
// an AssemblyResolutionException will be throwing here but it can work in the Windows OS environment as well.
339-
declDef = decl.Resolve ();
340-
}
341-
342333
if (insertNested)
343334
{
344335
buf.Append (NestedTypeSeparator);
345336
}
337+
346338
insertNested = true;
339+
TypeReference declDef = decl.Resolve () ?? decl;
347340
AppendTypeName (buf, declDef, context);
348341
int ac = DocUtils.GetGenericArgumentCount (declDef);
349342
int c = ac - prev;

mdoc/mdoc.Test/BasicTests.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System.Linq;
55
using System.Xml.Linq;
66
using Mono.Cecil;
7-
using Mono.Documentation.Framework;
87
using Mono.Documentation.Updater;
98

109
namespace mdoc.Test
@@ -23,7 +22,7 @@ protected TypeDefinition GetType(string filepath, string classname)
2322
if (!moduleCash.ContainsKey(filepath))
2423
{
2524
var fullpath = Path.Combine (Path.GetDirectoryName (this.GetType ().Module.Assembly.Location), filepath);
26-
var resolver = new DefaultAssemblyResolver ();
25+
var resolver = new DotnetCoreAssemblyResolver ();
2726
var testAssemblyPath = Path.GetDirectoryName (this.GetType ().Module.Assembly.Location);
2827
resolver.AddSearchDirectory (testAssemblyPath);
2928

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
using Mono.Cecil;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.IO;
5+
using System.Linq;
6+
7+
namespace mdoc.Test
8+
{
9+
// Fix DefaultAssemblyResolver don't load .NET Core platform assemblies in macOS, WSL, and Ubuntu OS environment.
10+
public class DotnetCoreAssemblyResolver : DefaultAssemblyResolver
11+
{
12+
public DotnetCoreAssemblyResolver()
13+
{
14+
AddDotnetCoreToSearchDirectory();
15+
}
16+
17+
private void AddDotnetCoreToSearchDirectory()
18+
{
19+
if (Environment.OSVersion.Platform == PlatformID.Unix ||
20+
Environment.OSVersion.Platform == PlatformID.MacOSX)
21+
{
22+
var latestDotnetCorePath = GetLatestPlatformAssembliesPath();
23+
if (string.IsNullOrEmpty(latestDotnetCorePath))
24+
{
25+
Console.WriteLine("The platform assemblies of .NET Core was not found, do you have .NET Core installed?");
26+
}
27+
28+
AddSearchDirectory(latestDotnetCorePath);
29+
}
30+
}
31+
32+
private string GetLatestPlatformAssembliesPath()
33+
{
34+
SortedList<Version, string> versionResults = new SortedList<Version, string>();
35+
foreach (var installedSdkVersion in GetInstalledSdkVersions())
36+
{
37+
if (File.Exists(Path.Combine(installedSdkVersion, "System.dll")))
38+
{
39+
Version sdkVersion;
40+
DirectoryInfo sdkDirectoryInfo = new DirectoryInfo(installedSdkVersion);
41+
if (Version.TryParse(sdkDirectoryInfo.Name, out sdkVersion))
42+
{
43+
versionResults.Add(sdkVersion, installedSdkVersion);
44+
}
45+
}
46+
}
47+
48+
return versionResults.LastOrDefault().Value;
49+
}
50+
51+
private string[] GetInstalledSdkVersions()
52+
{
53+
var dotnetCorePackagesPath = GetDotnetCorePath();
54+
if (Directory.Exists(dotnetCorePackagesPath))
55+
{
56+
return Directory.GetDirectories(dotnetCorePackagesPath);
57+
}
58+
59+
return Array.Empty<string>();
60+
}
61+
62+
private string GetDotnetCorePath()
63+
{
64+
var dotnetCorePath = GetMacOSDotnetCorePath();
65+
if (string.IsNullOrEmpty(dotnetCorePath))
66+
{
67+
dotnetCorePath = GetLinuxDotnetCorePath();
68+
}
69+
70+
if (!Directory.Exists(dotnetCorePath))
71+
{
72+
Console.WriteLine($"The path of .NET Core was not found, do you have .NET Core installed? {dotnetCorePath}");
73+
}
74+
75+
return dotnetCorePath;
76+
}
77+
78+
private string GetMacOSDotnetCorePath()
79+
{
80+
var macOSDotnetCorePath = GetAzureMacOSDotnetCorePath();
81+
if (string.IsNullOrEmpty(macOSDotnetCorePath))
82+
{
83+
// Hard code the local path of .NET Core for macOS.
84+
macOSDotnetCorePath = "/usr/local/share/dotnet/shared/Microsoft.NETCore.App";
85+
}
86+
87+
return Directory.Exists(macOSDotnetCorePath) ? macOSDotnetCorePath : string.Empty;
88+
}
89+
90+
private string GetAzureMacOSDotnetCorePath()
91+
{
92+
var azureMacOSDotnetCorePath = Environment.GetEnvironmentVariable("DOTNET_ROOT");
93+
if (!string.IsNullOrEmpty(azureMacOSDotnetCorePath))
94+
{
95+
return Path.Combine(azureMacOSDotnetCorePath, "shared/Microsoft.NETCore.App");
96+
}
97+
98+
return string.Empty;
99+
}
100+
101+
private string GetLinuxDotnetCorePath()
102+
{
103+
return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "dotnet/shared/Microsoft.NETCore.App");
104+
}
105+
}
106+
}

mdoc/mdoc.Test/NullableReferenceTypesTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ public void TypeName(string returnType, string methodName)
131131
[TestCase("NullableGenericValueTypeOfReferenceType", "ReadOnlySpan<string> s1, ReadOnlySpan<string?> s2, ReadOnlySpan<string> s3")]
132132
[TestCase("NullableAndNonNullableInterfaceOfValueType", "ICollection<int> collection1, ICollection<int>? collection2, ICollection<int> collection3")]
133133
[TestCase("NullableAndNonNullableInterfaceOfReferenceType", "ICollection<string> collection1, ICollection<string>? collection2, ICollection<string> collection3")]
134+
[TestCase("NonNullableValueTypeWithOutModifier", "string? value, out bool result")]
135+
[TestCase("NonNullableValueTypeWithRefModifier", "string? value, ref bool result")]
134136
public void MethodParameter(string methodName, string methodParameter)
135137
{
136138
TestMethodSignature(NullableReferenceTypesAssemblyPath, "mdoc.Test.NullableReferenceTypes.MethodParameter",

mdoc/mdoc.Test/mdoc.Test.NullableReferenceTypes/mdoc.Test.NullableReferenceTypes/MethodParameter.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,14 @@ public void NullableAndNonNullableInterfaceOfValueType(ICollection<int> collecti
3636
public void NullableAndNonNullableInterfaceOfReferenceType(ICollection<string> collection1, ICollection<string>? collection2, ICollection<string> collection3)
3737
{
3838
}
39+
40+
public void NonNullableValueTypeWithOutModifier(string? value, out bool result)
41+
{
42+
result = false;
43+
}
44+
45+
public void NonNullableValueTypeWithRefModifier(string? value, ref bool result)
46+
{
47+
}
3948
}
4049
}

mdoc/mdoc.Test/mdoc.Test.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
<Compile Include="CppWinRtMembersTests.cs" />
7878
<Compile Include="CppWinRtFormatterTests.cs" />
7979
<Compile Include="Enumeration\AttachedEntityTests.cs" />
80+
<Compile Include="DotnetCoreAssemblyResolver.cs" />
8081
<Compile Include="FrameworkIndexHelperTests.cs" />
8182
<Compile Include="DocUtilsFSharpTests.cs" />
8283
<Compile Include="DocUtilsTests.cs" />

0 commit comments

Comments
 (0)