Skip to content

Commit 085df17

Browse files
authored
Constraints on parameter types allow ref struct (#727)
* update * add unit test * update * update * update * update * update * update * update * update ut case * update * update * update * upgrade version
1 parent 94e41b7 commit 085df17

File tree

6 files changed

+33
-3
lines changed

6 files changed

+33
-3
lines changed

external/Test/AllowsRefStructDemo.dll

4 KB
Binary file not shown.

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.9.3.8";
6+
public static string MonoVersion = "5.9.4";
77
public const string DocId = "DocId";
88
public const string CppCli = "C++ CLI";
99
public const string CppCx = "C++ CX";

mdoc/Mono.Documentation/MDocUpdater.Member.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ internal static void MakeTypeParameterConstraints(XmlElement root, XmlElement e,
4444
AppendElementText(ce, "ParameterAttribute", "NotNullableValueTypeConstraint");
4545
if ((attrs & GenericParameterAttributes.ReferenceTypeConstraint) != 0)
4646
AppendElementText(ce, "ParameterAttribute", "ReferenceTypeConstraint");
47+
// Check for 'allows ref struct' constraint
48+
if ((attrs & (GenericParameterAttributes)0x0020) != 0) // Assuming 0x0020 is the flag for 'allows ref struct'
49+
AppendElementText(ce, "ParameterAttribute", "AllowByRefLike");
4750

4851
#if NEW_CECIL
4952
foreach (GenericParameterConstraint c in constraints)

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,9 +314,10 @@ private StringBuilder AppendConstraints (StringBuilder buf, IList<GenericParamet
314314
bool isref = (attrs & GenericParameterAttributes.ReferenceTypeConstraint) != 0;
315315
bool isvt = (attrs & GenericParameterAttributes.NotNullableValueTypeConstraint) != 0;
316316
bool isnew = (attrs & GenericParameterAttributes.DefaultConstructorConstraint) != 0;
317+
bool isAllowsRefStruct = (attrs & (GenericParameterAttributes)0x0020) != 0; // Assuming 0x0020 is the flag for 'allows ref struct'
317318
bool comma = false;
318319

319-
if (!isref && !isvt && !isnew && constraints.Count == 0)
320+
if (!isref && !isvt && !isAllowsRefStruct && !isnew && constraints.Count == 0)
320321
continue;
321322
buf.Append (" where ").Append (genArg.Name).Append (" : ");
322323
if (isref)
@@ -350,6 +351,14 @@ private StringBuilder AppendConstraints (StringBuilder buf, IList<GenericParamet
350351
buf.Append (", ");
351352
buf.Append ("new()");
352353
}
354+
355+
// Handle 'allows ref struct' constraint
356+
if (isAllowsRefStruct)
357+
{
358+
if (comma || constraints.Count > 0 || isnew)
359+
buf.Append(", ");
360+
buf.Append("allows ref struct");
361+
}
353362
}
354363
return buf;
355364
}

mdoc/mdoc.Test/FormatterTests.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,24 @@ public void CSharpStaticEventImplementation(string typeFullName, string eventNam
601601
TestEventSignature(staticVirtualMemberDllPath, typeFullName, eventName, expectedSignature);
602602
}
603603

604+
[TestCase("AllowsRefStructDemo.IRefStructProcessor`1",
605+
"public interface IRefStructProcessor<T> where T : allows ref struct")]
606+
public void CSharpAllowsRefStructForTypeTest(string typeFullName, string expectedSignature)
607+
{
608+
var allowsRefStructDllPath = "../../../../external/Test/AllowsRefStructDemo.dll";
609+
TestTypeSignature(allowsRefStructDllPath, typeFullName, expectedSignature);
610+
}
611+
612+
[TestCase("AllowsRefStructDemo.Immutable", "Update",
613+
"public bool Update<TArg> (TArg transformerArgument) where TArg : new(), allows ref struct;")]
614+
[TestCase("AllowsRefStructDemo.RefStructHandler", "Handle",
615+
"public void Handle<T> (ref T item) where T : new(), allows ref struct;")]
616+
public void CSharpAllowsRefStructForMemberTest(string typeFullName, string methodName, string expectedSignature)
617+
{
618+
var allowsRefStructDllPath = "../../../../external/Test/AllowsRefStructDemo.dll";
619+
TestMethodSignature(allowsRefStructDllPath, typeFullName, methodName, expectedSignature);
620+
}
621+
604622
#region Helper Methods
605623
string RealTypeName(string name){
606624
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.3.8</version>
5+
<version>5.9.4</version>
66
<title>mdoc</title>
77
<authors>Microsoft</authors>
88
<owners>Microsoft</owners>

0 commit comments

Comments
 (0)