Skip to content

Commit 8257f37

Browse files
committed
Adding test for icsharpcode#1158 regarding properties used as ref parameter in extension methods
1 parent abea701 commit 8257f37

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

Tests/CSharp/ExpressionTests/ByRefTests.cs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -913,4 +913,56 @@ public static void LogAndReset(ref int arg)
913913
}");
914914
}
915915

916+
[Fact]
917+
public async Task ExtensionMethodsRefPropertyParameterAsync()
918+
{
919+
await TestConversionVisualBasicToCSharpAsync(@"
920+
Public Class ExtensionMethodsRefPropertyParameter
921+
Public Property Number As Integer = 3
922+
Public Sub WithExtensionMethod()
923+
Number.NegEx()
924+
End Sub
925+
Public Sub WithMethod()
926+
Neg(Number)
927+
End Sub
928+
End Class
929+
930+
Public Module MathEx
931+
<Extension()>
932+
Public Sub NegEx(ByRef num As Integer)
933+
num = -num
934+
End Sub
935+
Public Sub Neg(ByRef num As Integer)
936+
num = -num
937+
End Sub
938+
End Module", @"
939+
public partial class ExtensionMethodsRefPropertyParameter
940+
{
941+
public int Number { get; set; } = 3;
942+
public void WithExtensionMethod()
943+
{
944+
int argnum = Number;
945+
argnum.NegEx();
946+
Number = argnum;
947+
}
948+
public void WithMethod()
949+
{
950+
int argnum = Number;
951+
MathEx.Neg(ref argnum);
952+
Number = argnum;
953+
}
954+
}
955+
956+
public static partial class MathEx
957+
{
958+
public static void NegEx(this ref int num)
959+
{
960+
num = -num;
961+
}
962+
public static void Neg(ref int num)
963+
{
964+
num = -num;
965+
}
966+
}");
967+
}
916968
}

0 commit comments

Comments
 (0)