Skip to content

Commit

Permalink
Adding test for icsharpcode#1158 regarding properties used as ref par…
Browse files Browse the repository at this point in the history
…ameter in extension methods
  • Loading branch information
gaschd committed Nov 11, 2024
1 parent abea701 commit 8257f37
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions Tests/CSharp/ExpressionTests/ByRefTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -913,4 +913,56 @@ public static void LogAndReset(ref int arg)
}");
}

[Fact]
public async Task ExtensionMethodsRefPropertyParameterAsync()
{
await TestConversionVisualBasicToCSharpAsync(@"
Public Class ExtensionMethodsRefPropertyParameter
Public Property Number As Integer = 3
Public Sub WithExtensionMethod()
Number.NegEx()
End Sub
Public Sub WithMethod()
Neg(Number)
End Sub
End Class
Public Module MathEx
<Extension()>
Public Sub NegEx(ByRef num As Integer)
num = -num
End Sub
Public Sub Neg(ByRef num As Integer)
num = -num
End Sub
End Module", @"
public partial class ExtensionMethodsRefPropertyParameter
{
public int Number { get; set; } = 3;
public void WithExtensionMethod()
{
int argnum = Number;
argnum.NegEx();
Number = argnum;
}
public void WithMethod()
{
int argnum = Number;
MathEx.Neg(ref argnum);
Number = argnum;
}
}
public static partial class MathEx
{
public static void NegEx(this ref int num)
{
num = -num;
}
public static void Neg(ref int num)
{
num = -num;
}
}");
}
}

0 comments on commit 8257f37

Please sign in to comment.