Skip to content

Commit cd79680

Browse files
authored
Support ref readonly parameters (#712) (#737)
Add support for correct rendering of "ref readonly" parameter in C# method signature documentation.
2 parents 3aec8b1 + 6935391 commit cd79680

File tree

5 files changed

+15
-4
lines changed

5 files changed

+15
-4
lines changed
3.5 KB
Binary file not shown.

mdoc/Consts.cs

Lines changed: 2 additions & 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.9.4";
6+
public static string MonoVersion = "5.9.5";
77
public const string DocId = "DocId";
88
public const string CppCli = "C++ CLI";
99
public const string CppCx = "C++ CX";
@@ -49,6 +49,7 @@ public static class Consts
4949
public const string CompilerGeneratedAttribute = "System.Runtime.CompilerServices.CompilerGeneratedAttribute";
5050
public const string IsByRefLikeAttribute = "System.Runtime.CompilerServices.IsByRefLikeAttribute";
5151
public const string IsReadOnlyAttribute = "System.Runtime.CompilerServices.IsReadOnlyAttribute";
52+
public const string RequiresLocationAttribute = "System.Runtime.CompilerServices.RequiresLocationAttribute";
5253
public const string InAttribute = "System.Runtime.InteropServices.InAttribute";
5354
public const string OutAttribute = "System.Runtime.InteropServices.OutAttribute";
5455
public const string TupleElementNamesAttribute = "System.Runtime.CompilerServices.TupleElementNamesAttribute";

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ private StringBuilder AppendParameters (StringBuilder buf, MethodDefinition meth
619619
protected override StringBuilder AppendParameter(StringBuilder buf, ParameterDefinition parameter)
620620
{
621621
TypeReference parameterType = parameter.ParameterType;
622-
var refType = new BitArray(3);
622+
var refType = new BitArray(4);
623623

624624
if (parameter.HasCustomAttributes)
625625
{
@@ -650,14 +650,18 @@ protected override StringBuilder AppendParameter(StringBuilder buf, ParameterDef
650650
{
651651
refType.Set(0, true);
652652
}
653+
else if (parameter.IsIn && DocUtils.HasCustomAttribute(parameter, Consts.RequiresLocationAttribute))
654+
{
655+
refType.Set(3, true);
656+
}
653657
else
654658
{
655659
refType.Set(2, true);
656660
}
657661
parameterType = byReferenceType.ElementType;
658662
}
659663

660-
buf.Append(refType.Get(0) ? "in " : (refType.Get(1) ? "out " : (refType.Get(2) ? "ref ": "")));
664+
buf.Append(refType.Get(0) ? "in " : (refType.Get(1) ? "out " : (refType.Get(2) ? "ref ": (refType.Get(3) ? "ref readonly " : ""))));
661665

662666
if (parameter.HasCustomAttributes)
663667
{

mdoc/mdoc.Test/FormatterTests.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,12 @@ public void CSharpAllowsRefStructForMemberTest(string typeFullName, string metho
619619
TestMethodSignature(allowsRefStructDllPath, typeFullName, methodName, expectedSignature);
620620
}
621621

622+
[TestCase("SomeClass", "MethodWithRefReadOnlyParam", "public void MethodWithRefReadOnlyParam (ref readonly int i);")]
623+
public void CSharpRefReadonlyTest(string typeFullName, string methodName, string expectedSignature)
624+
{
625+
TestMethodSignature("../../../../external/Test/RefReadonlyParameter.dll", typeFullName, methodName, expectedSignature);
626+
}
627+
622628
#region Helper Methods
623629
string RealTypeName(string name){
624630
switch (name) {

mdoc/mdoc.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package >
33
<metadata>
44
<id>mdoc</id>
5-
<version>5.9.4</version>
5+
<version>5.9.5</version>
66
<title>mdoc</title>
77
<authors>Microsoft</authors>
88
<owners>Microsoft</owners>

0 commit comments

Comments
 (0)