Skip to content
Merged
Show file tree
Hide file tree
Changes from 13 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
Binary file added external/Test/AllowsRefStructDemo.dll
Binary file not shown.
3 changes: 3 additions & 0 deletions mdoc/Mono.Documentation/MDocUpdater.Member.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ internal static void MakeTypeParameterConstraints(XmlElement root, XmlElement e,
AppendElementText(ce, "ParameterAttribute", "NotNullableValueTypeConstraint");
if ((attrs & GenericParameterAttributes.ReferenceTypeConstraint) != 0)
AppendElementText(ce, "ParameterAttribute", "ReferenceTypeConstraint");
// Check for 'allows ref struct' constraint
if ((attrs & (GenericParameterAttributes)0x0020) != 0) // Assuming 0x0020 is the flag for 'allows ref struct'
AppendElementText(ce, "ParameterAttribute", "AllowByRefLike");

#if NEW_CECIL
foreach (GenericParameterConstraint c in constraints)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,9 +314,10 @@ private StringBuilder AppendConstraints (StringBuilder buf, IList<GenericParamet
bool isref = (attrs & GenericParameterAttributes.ReferenceTypeConstraint) != 0;
bool isvt = (attrs & GenericParameterAttributes.NotNullableValueTypeConstraint) != 0;
bool isnew = (attrs & GenericParameterAttributes.DefaultConstructorConstraint) != 0;
bool isAllowsRefStruct = (attrs & (GenericParameterAttributes)0x0020) != 0; // Assuming 0x0020 is the flag for 'allows ref struct'
bool comma = false;

if (!isref && !isvt && !isnew && constraints.Count == 0)
if (!isref && !isvt && !isAllowsRefStruct && !isnew && constraints.Count == 0)
continue;
buf.Append (" where ").Append (genArg.Name).Append (" : ");
if (isref)
Expand Down Expand Up @@ -350,6 +351,14 @@ private StringBuilder AppendConstraints (StringBuilder buf, IList<GenericParamet
buf.Append (", ");
buf.Append ("new()");
}

// Handle 'allows ref struct' constraint
if (isAllowsRefStruct)
{
if (comma || constraints.Count > 0 || isnew)
buf.Append(", ");
buf.Append("allows ref struct");
}
}
return buf;
}
Expand Down
18 changes: 18 additions & 0 deletions mdoc/mdoc.Test/FormatterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,24 @@ public void CSharpStaticEventImplementation(string typeFullName, string eventNam
TestEventSignature(staticVirtualMemberDllPath, typeFullName, eventName, expectedSignature);
}

[TestCase("AllowsRefStructDemo.IRefStructProcessor`1",
"public interface IRefStructProcessor<T> where T : allows ref struct")]
public void CSharpAllowsRefStructForTypeTest(string typeFullName, string expectedSignature)
{
var allowsRefStructDllPath = "../../../../external/Test/AllowsRefStructDemo.dll";
TestTypeSignature(allowsRefStructDllPath, typeFullName, expectedSignature);
}

[TestCase("AllowsRefStructDemo.Immutable", "Update",
"public bool Update<TArg> (TArg transformerArgument) where TArg : new(), allows ref struct;")]
[TestCase("AllowsRefStructDemo.RefStructHandler", "Handle",
"public void Handle<T> (ref T item) where T : new(), allows ref struct;")]
public void CSharpAllowsRefStructForMemberTest(string typeFullName, string methodName, string expectedSignature)
{
var allowsRefStructDllPath = "../../../../external/Test/AllowsRefStructDemo.dll";
TestMethodSignature(allowsRefStructDllPath, typeFullName, methodName, expectedSignature);
}

#region Helper Methods
string RealTypeName(string name){
switch (name) {
Expand Down