From 8257f37fc7b1432ffbe1071fa35086fb3ae41d94 Mon Sep 17 00:00:00 2001 From: gaschd Date: Mon, 11 Nov 2024 22:28:39 +0100 Subject: [PATCH] Adding test for #1158 regarding properties used as ref parameter in extension methods --- Tests/CSharp/ExpressionTests/ByRefTests.cs | 52 ++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/Tests/CSharp/ExpressionTests/ByRefTests.cs b/Tests/CSharp/ExpressionTests/ByRefTests.cs index 536d224b9..72e8584e0 100644 --- a/Tests/CSharp/ExpressionTests/ByRefTests.cs +++ b/Tests/CSharp/ExpressionTests/ByRefTests.cs @@ -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 + + 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; + } +}"); + } } \ No newline at end of file