diff --git a/mdoc/Consts.cs b/mdoc/Consts.cs index db2772edc..3ef0b9364 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.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"; diff --git a/mdoc/Mono.Documentation/Updater/Formatters/CSharpFullMemberFormatter.cs b/mdoc/Mono.Documentation/Updater/Formatters/CSharpFullMemberFormatter.cs index 37c0da244..811ff3be1 100644 --- a/mdoc/Mono.Documentation/Updater/Formatters/CSharpFullMemberFormatter.cs +++ b/mdoc/Mono.Documentation/Updater/Formatters/CSharpFullMemberFormatter.cs @@ -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) { @@ -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 "); } diff --git a/mdoc/mdoc.Test/FormatterTests.cs b/mdoc/mdoc.Test/FormatterTests.cs index 2e16f65ff..ce1009fed 100644 --- a/mdoc/mdoc.Test/FormatterTests.cs +++ b/mdoc/mdoc.Test/FormatterTests.cs @@ -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); @@ -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 diff --git a/mdoc/mdoc.Test/SampleClasses/ReadonlyRefClass.cs b/mdoc/mdoc.Test/SampleClasses/ReadonlyRefClass.cs index 59f356728..2ff9d09ad 100644 --- a/mdoc/mdoc.Test/SampleClasses/ReadonlyRefClass.cs +++ b/mdoc/mdoc.Test/SampleClasses/ReadonlyRefClass.cs @@ -1,4 +1,6 @@ -namespace mdoc.Test.SampleClasses +using System.Runtime.InteropServices; + +namespace mdoc.Test.SampleClasses { public class ReadonlyRefClass { @@ -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 @@ -25,5 +29,7 @@ public class GenericRefClass 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; } } diff --git a/mdoc/mdoc.Test/SampleClasses/StructWithReadOnlyMethod.cs b/mdoc/mdoc.Test/SampleClasses/StructWithReadOnlyMethod.cs index baf8f7af7..b61b2811b 100644 --- a/mdoc/mdoc.Test/SampleClasses/StructWithReadOnlyMethod.cs +++ b/mdoc/mdoc.Test/SampleClasses/StructWithReadOnlyMethod.cs @@ -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; } @@ -9,5 +9,7 @@ public readonly double Sum() { return X + Y; } + + readonly int Struct_Interface_A.GetNum() => 1; } } diff --git a/mdoc/mdoc.Test/SampleClasses/Struct_Interface_A.cs b/mdoc/mdoc.Test/SampleClasses/Struct_Interface_A.cs new file mode 100644 index 000000000..0529e0265 --- /dev/null +++ b/mdoc/mdoc.Test/SampleClasses/Struct_Interface_A.cs @@ -0,0 +1,7 @@ +namespace mdoc.Test.SampleClasses +{ + public interface Struct_Interface_A + { + int GetNum(); + } +} diff --git a/mdoc/mdoc.nuspec b/mdoc/mdoc.nuspec index 0bf49a818..6483827a7 100644 --- a/mdoc/mdoc.nuspec +++ b/mdoc/mdoc.nuspec @@ -2,12 +2,12 @@ mdoc - 5.8.6.1 + 5.8.7 mdoc Microsoft Microsoft https://github.com/mono/api-doc-tools - https://github.com/mono/api-doc-tools/blob/main/LICENSE.md + MIT true .NET API Documentation toolchain © Microsoft Corporation. All rights reserved.