Skip to content

Commit bd84cee

Browse files
authored
support scoped keyword in method parameters (#655)
* support scoped keyword * renaming
1 parent 215b2a9 commit bd84cee

4 files changed

Lines changed: 25 additions & 3 deletions

File tree

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,13 @@ protected override StringBuilder AppendParameter(StringBuilder buf, ParameterDef
608608
TypeReference parameterType = parameter.ParameterType;
609609
var refType = new BitArray(3);
610610

611+
if (parameter.HasCustomAttributes)
612+
{
613+
var isScoped = parameter.CustomAttributes.Any(ca => ca.AttributeType.Name == "LifetimeAnnotationAttribute");
614+
if (isScoped)
615+
buf.AppendFormat("scoped ");
616+
}
617+
611618
if (parameterType is RequiredModifierType requiredModifierType)
612619
{
613620
switch(requiredModifierType.ModifierType.FullName)

mdoc/mdoc.Test/FormatterTests.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,15 @@ public void CSharpRefReturnMethodTest(Type type, string methodName, string expec
271271
Assert.AreEqual(expectedSignature, actualSignature);
272272
}
273273

274+
[TestCase(typeof(SomeClass), "TestScopedParams", "public ref T TestScopedParams<T> (scoped in T p1, out T p2, scoped ref T p3);")]
275+
public void CSharpScopedParamsTest(Type type, string methodName, string expectedSignature)
276+
{
277+
var member = GetMethod(type, m => m.Name == methodName);
278+
var actualSignature = formatter.GetDeclaration(member);
279+
Assert.AreEqual(expectedSignature, actualSignature);
280+
}
281+
282+
274283
[TestCase(typeof(ReadonlyRefClass), "RefProperty", "public ref int RefProperty { get; }")]
275284
[TestCase(typeof(ReadonlyRefClass), "Item", "public ref readonly int this[int index] { get; }")]
276285
[TestCase(typeof(GenericRefClass<>), "RefProperty", "public ref T RefProperty { get; }")]

mdoc/mdoc.Test/SampleClasses/SomeClass.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using Mono.Cecil.Cil;
2+
using System;
23
using Windows.Foundation.Metadata;
34

45
namespace mdoc.Test.SampleClasses
@@ -98,6 +99,11 @@ public void get_Method()
9899
{
99100
}
100101

102+
public ref T TestScopedParams<T>(scoped in T p1, scoped out T p2, scoped ref T p3)
103+
{
104+
throw new PlatformNotSupportedException();
105+
}
106+
101107
public event EventHandler<object> AppMemoryUsageIncreased;
102108
public static event EventHandler<object> StaticEvent;
103109
private static event EventHandler<object> PrivateEvent;

mdoc/mdoc.Test/mdoc.Test.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
99
<OutputPath>bin\Debug</OutputPath>
1010
<DefineConstants>DEBUG;</DefineConstants>
11-
<LangVersion>latest</LangVersion>
11+
<LangVersion>preview</LangVersion>
1212
</PropertyGroup>
1313
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
1414
<OutputPath>bin\Release</OutputPath>
15-
<LangVersion>latest</LangVersion>
15+
<LangVersion>preview</LangVersion>
1616
</PropertyGroup>
1717
<PropertyGroup>
1818
<RunPostBuildEvent>Always</RunPostBuildEvent>

0 commit comments

Comments
 (0)