Skip to content

Commit

Permalink
Add object browser support for ref struct interfaces (#73621)
Browse files Browse the repository at this point in the history
* Add object browser support for ref struct interfaces

The description building code for method constraints in the object browser had not yet been modified to support ITypeParameterSymbol.AllowsRefLikeType

This is in support of the "allows ref struct" on interfaces feature outlined here: #72124

This ref structs for interfaces feature was merged via this PR: #73567
  • Loading branch information
ToddGrun authored May 22, 2024
1 parent 35e4223 commit b8395ee
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
14 changes: 13 additions & 1 deletion src/VisualStudio/CSharp/Impl/ObjectBrowser/DescriptionBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,8 @@ private void BuildConstraints(ITypeParameterSymbol typeParameterSymbol)
if (typeParameterSymbol.ConstraintTypes.Length == 0 &&
!typeParameterSymbol.HasConstructorConstraint &&
!typeParameterSymbol.HasReferenceTypeConstraint &&
!typeParameterSymbol.HasValueTypeConstraint)
!typeParameterSymbol.HasValueTypeConstraint &&
!typeParameterSymbol.AllowsRefLikeType)
{
return;
}
Expand Down Expand Up @@ -396,6 +397,17 @@ private void BuildConstraints(ITypeParameterSymbol typeParameterSymbol)
}

AddText("new()");
isFirst = false;
}

if (typeParameterSymbol.AllowsRefLikeType)
{
if (!isFirst)
{
AddComma();
}

AddText("allows ref struct");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -728,13 +728,18 @@ $" {String.Format(ServicesVSResources.Member_of_0, "UnsafeC")}")
using System.Collections.Generic;
class C
{
T M<T, U, V>()
T M1<T, U, V>()
where T : class, new()
where U : V
where V : List<T>
{
return null;
}

void M2<T>(T t)
where T : IDisposable, allows ref struct
{
}
}
</Code>

Expand All @@ -744,12 +749,19 @@ class C
list = list.GetTypeList(0)
list = list.GetMemberList(0)

list.VerifyImmediateMemberDescriptions(
"private T M<T, U, V>()" & vbCrLf &
Dim memberDescription1 =
"private T M1<T, U, V>()" & vbCrLf &
vbTab & "where T : class, new()" & vbCrLf &
vbTab & "where U : V" & vbCrLf &
vbTab & "where V : System.Collections.Generic.List<T>" & vbCrLf &
$" {String.Format(ServicesVSResources.Member_of_0, "C")}")
$" {String.Format(ServicesVSResources.Member_of_0, "C")}"

Dim memberDescription2 =
"private void M2<T>(T t)" & vbCrLf &
vbTab & "where T : IDisposable, allows ref struct" & vbCrLf &
$" {String.Format(ServicesVSResources.Member_of_0, "C")}"

list.VerifyImmediateMemberDescriptions(memberDescription1, memberDescription2)
End Using
End Sub

Expand Down

0 comments on commit b8395ee

Please sign in to comment.