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
2 changes: 1 addition & 1 deletion mdoc/Consts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace Mono.Documentation
{
public static class Consts
{
public static string MonoVersion = "5.8.6.1";
public static string MonoVersion = "5.8.7";
public const string DocId = "DocId";
public const string CppCli = "C++ CLI";
public const string CppCx = "C++ CX";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -503,19 +503,19 @@ protected override StringBuilder AppendModifiers (StringBuilder buf, MethodDefin
{
string modifiers = String.Empty;
if (method.IsStatic) modifiers += " static";
TypeDefinition declType = (TypeDefinition)method.DeclaringType;
if (declType.IsValueType && DocUtils.HasCustomAttribute(method, Consts.IsReadOnlyAttribute))
{
modifiers += " readonly";
}
if (method.IsVirtual && !method.IsAbstract)
{
if ((method.Attributes & MethodAttributes.NewSlot) != 0) modifiers += " virtual";
else modifiers += " override";
}
TypeDefinition declType = (TypeDefinition)method.DeclaringType;
if (method.IsAbstract && !declType.IsInterface) modifiers += " abstract";
if (method.IsFinal) modifiers += " sealed";
if (modifiers == " virtual sealed") modifiers = "";
if (declType.IsValueType && DocUtils.HasCustomAttribute(method, Consts.IsReadOnlyAttribute))
{
modifiers += buf.Length == 0 ? "readonly" : " readonly";
}

switch (method.Name)
{
Expand Down Expand Up @@ -593,13 +593,18 @@ private StringBuilder AppendParameter (StringBuilder buf, ParameterDefinition pa
{
TypeReference parameterType = parameter.ParameterType;

if (parameterType is RequiredModifierType requiredModifierType)
{
parameterType = requiredModifierType.ElementType;
}

if (parameterType is ByReferenceType byReferenceType)
{
if (parameter.IsOut)
{
buf.Append ("out ");
}
else if(parameter.IsIn)
else if(parameter.IsIn && DocUtils.HasCustomAttribute(parameter, Consts.IsReadOnlyAttribute))
{
buf.Append("in ");
}
Expand Down
11 changes: 7 additions & 4 deletions mdoc/mdoc.Test/FormatterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,11 @@ public void FuncParams()
[TestCase(typeof(ReadonlyRefClass), "Ref", "public ref int Ref ();")]
[TestCase(typeof(ReadonlyRefClass), "ReadonlyRef", "public ref readonly int ReadonlyRef ();")]
[TestCase(typeof(ReadonlyRefClass), "RefInAndOutMethod", "public void RefInAndOutMethod (ref int a, in int b, out int c);")]
[TestCase(typeof(ReadonlyRefClass), "InAttributeMethod", "public void InAttributeMethod (ref int a, in int b, out int c);")]
[TestCase(typeof(GenericRefClass<>), "Ref", "public ref T Ref ();")]
[TestCase(typeof(GenericRefClass<>), "ReadonlyRef", "public ref readonly T ReadonlyRef ();")]
[TestCase(typeof(GenericRefClass<>), "RefInAndOutMethod", "public void RefInAndOutMethod (ref T a, in T b, out T c);")]
[TestCase(typeof(GenericRefClass<>), "InAttributeMethod", "public void InAttributeMethod (ref T a, in T b, out T c);")]
public void CSharpRefReturnMethodTest(Type type, string methodName, string expectedSignature)
{
var member = GetMethod(type, m => m.Name == methodName);
Expand Down Expand Up @@ -409,12 +411,13 @@ public void CSharpReadOnlyRefStructTest()
Assert.AreEqual("public readonly ref struct ReadOnlyRefStruct", typeSignature);
}

[Test]
public void CSharpReadOnlyMemberStructTest()
[TestCase("Sum", "public readonly double Sum ();")]
[TestCase("GetNum", "readonly int Struct_Interface_A.GetNum ();")]
public void CSharpReadOnlyMemberStructTest(string methodName, string expectedSignature)
{
var method = GetMethod(typeof(SampleClasses.StructWithReadOnlyMethod), m => m.Name == "Sum");
var method = GetMethod(typeof(SampleClasses.StructWithReadOnlyMethod), m => m.Name.Contains(methodName));
var methodSignature = formatter.GetDeclaration(method);
Assert.AreEqual("public readonly double Sum ();", methodSignature);
Assert.AreEqual(expectedSignature, methodSignature);
}

#region Helper Methods
Expand Down
8 changes: 7 additions & 1 deletion mdoc/mdoc.Test/SampleClasses/ReadonlyRefClass.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace mdoc.Test.SampleClasses
using System.Runtime.InteropServices;

namespace mdoc.Test.SampleClasses
{
public class ReadonlyRefClass
{
Expand All @@ -12,6 +14,8 @@ public class ReadonlyRefClass
public ref readonly int this[int index] => throw null;

public void RefInAndOutMethod(ref int a, in int b, out int c) => throw null;

public void InAttributeMethod([In] ref int a, [In] in int b, [Out] out int c) => throw null;
}

public class GenericRefClass<T>
Expand All @@ -25,5 +29,7 @@ public class GenericRefClass<T>
public ref readonly T this[int index] => throw null;

public void RefInAndOutMethod(ref T a, in T b, out T c) => throw null;

public void InAttributeMethod([In] ref T a, [In] in T b, [Out] out T c) => throw null;
}
}
4 changes: 3 additions & 1 deletion mdoc/mdoc.Test/SampleClasses/StructWithReadOnlyMethod.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace mdoc.Test.SampleClasses
{
public struct StructWithReadOnlyMethod
public struct StructWithReadOnlyMethod : Struct_Interface_A
{
public double X { get; set; }
public double Y { get; set; }
Expand All @@ -9,5 +9,7 @@ public readonly double Sum()
{
return X + Y;
}

readonly int Struct_Interface_A.GetNum() => 1;
}
}
7 changes: 7 additions & 0 deletions mdoc/mdoc.Test/SampleClasses/Struct_Interface_A.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace mdoc.Test.SampleClasses
{
public interface Struct_Interface_A
{
int GetNum();
}
}
4 changes: 2 additions & 2 deletions mdoc/mdoc.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
<package >
<metadata>
<id>mdoc</id>
<version>5.8.6.1</version>
<version>5.8.7</version>
<title>mdoc</title>
<authors>Microsoft</authors>
<owners>Microsoft</owners>
<projectUrl>https://github.com/mono/api-doc-tools</projectUrl>
<licenseUrl>https://github.com/mono/api-doc-tools/blob/main/LICENSE.md</licenseUrl>
<license type="expression">MIT</license>
<requireLicenseAcceptance>true</requireLicenseAcceptance>
<description>.NET API Documentation toolchain</description>
<copyright>© Microsoft Corporation. All rights reserved.</copyright>
Expand Down