Skip to content

Commit 669b604

Browse files
Ref improvements
1 parent cb0a723 commit 669b604

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

Tests/CSharp/ExpressionTests/ByRefTests.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,45 @@ public static Class1 Foo(ref Class1 c1)
325325
{
326326
return c1;
327327
}
328+
}");
329+
}
330+
331+
[Fact]
332+
public async Task AssignsBackToPropertyAsync()
333+
{
334+
await TestConversionVisualBasicToCSharpAsync(@"Public Class RefTestClass
335+
336+
Private Property Prop1 As Integer
337+
Private Property Prop2 As Integer = 1
338+
339+
Private Sub TakesRef(ByRef vrbTst As Integer) As Boolean
340+
vrbTst = vrbTst + Prop2
341+
Return vrbTst > 1
342+
End Sub
343+
344+
Private Sub UsesRef(someInt As Integer)
345+
If TakesRef(Prop1) OrElse TakesRef(Prop2) AndAlso TakesRef(Prop1)
346+
someInt += 1
347+
End If
348+
End Sub
349+
End Class", @"public class RefTestClass
350+
{
351+
private int Prop1 { get; set; }
352+
private int Prop2 { get; set; }
353+
354+
private bool TakesRef(ref int vrbTst)
355+
{
356+
vrbTst = vrbTst + Prop2;
357+
return vrbTst > 1;
358+
}
359+
360+
private void UsesRef(int someInt)
361+
{
362+
var argvrbTst = Prop;
363+
TakesRef(ref argvrbTst);
364+
Prop = argvrbTst; // Need to set value of property afterwards to maintain logic
365+
someInt += 1;
366+
}
328367
}");
329368
}
330369
}

0 commit comments

Comments
 (0)