Skip to content

Fixes for #1156, #1174, #1195#1223

Open
GrahamTheCoder wants to merge 16 commits intoicsharpcode:masterfrom
GrahamTheCoder:master
Open

Fixes for #1156, #1174, #1195#1223
GrahamTheCoder wants to merge 16 commits intoicsharpcode:masterfrom
GrahamTheCoder:master

Conversation

@GrahamTheCoder
Copy link
Member

@GrahamTheCoder GrahamTheCoder commented Feb 28, 2026

google-labs-jules bot and others added 12 commits February 27, 2026 02:24
When `ReDim Preserve` is used on a property in VB.NET, the C# converter was generating `Array.Resize(ref Property, ...)` which causes CS0206 because properties cannot be passed as `ref` or `out`.

This change updates `MethodBodyExecutableStatementVisitor.cs` to detect when the target of `ReDim Preserve` is a property or member access. In such cases, it generates a temporary variable, assigns the property value to it, resizes the temporary variable using `ref`, and then assigns the temporary variable back to the property.

Example:
VB.NET:
```vb
Public Property NumArray1 As Integer()
...
ReDim Preserve NumArray1(4)
```

Converted C#:
```csharp
var argNumArray1 = NumArray1;
Array.Resize(ref argNumArray1, 5);
NumArray1 = argNumArray1;
```

This ensures valid C# code is generated.

Co-authored-by: GrahamTheCoder <2490482+GrahamTheCoder@users.noreply.github.com>
When `ReDim Preserve` is used on a property in VB.NET, the C# converter was generating `Array.Resize(ref Property, ...)` which causes CS0206 because properties cannot be passed as `ref` or `out`.

This change updates `MethodBodyExecutableStatementVisitor.cs` to detect when the target of `ReDim Preserve` is a property or member access. In such cases, it generates a temporary variable, assigns the property value to it, resizes the temporary variable using `ref`, and then assigns the temporary variable back to the property.

Example:
VB.NET:
```vb
Public Property NumArray1 As Integer()
...
ReDim Preserve NumArray1(4)
```

Converted C#:
```csharp
var argNumArray1 = NumArray1;
Array.Resize(ref argNumArray1, 5);
NumArray1 = argNumArray1;
```

This ensures valid C# code is generated.

Co-authored-by: GrahamTheCoder <2490482+GrahamTheCoder@users.noreply.github.com>
When `ReDim Preserve` is used on a property in VB.NET, the C# converter was generating `Array.Resize(ref Property, ...)` which causes CS0206 because properties cannot be passed as `ref` or `out`.

This change updates `MethodBodyExecutableStatementVisitor.cs` to detect when the target of `ReDim Preserve` is a property or member access. In such cases, it generates a temporary variable, assigns the property value to it, resizes the temporary variable using `ref`, and then assigns the temporary variable back to the property.

Example:
VB.NET:
```vb
Public Property NumArray1 As Integer()
...
ReDim Preserve NumArray1(4)
```

Converted C#:
```csharp
var argNumArray1 = NumArray1;
Array.Resize(ref argNumArray1, 5);
NumArray1 = argNumArray1;
```

This ensures valid C# code is generated. Code generation was also refactored to remove duplicate syntax logic for cleaner compilation.

Co-authored-by: GrahamTheCoder <2490482+GrahamTheCoder@users.noreply.github.com>
Modified IsSubPartOfConditionalAccess to recursively check if a member access is part of the WhenNotNull branch of a ConditionalAccessExpression, handling nested conditional accesses. This ensures that the expression part (LHS) of a conditional access is correctly identified as not being part of the binding chain, allowing it to be resolved to the With block variable.

Added regression test WithBlockWithNullConditionalAccessAsync.

Co-authored-by: GrahamTheCoder <2490482+GrahamTheCoder@users.noreply.github.com>
…y-1508587937501568863

Fix ReDim Preserve on property generating invalid ref code
…l-conditional-12294486853097276888

Fix VB With block conversion with null-conditional operator
@GrahamTheCoder GrahamTheCoder changed the title Fixes for #1156, #1174 and probably #1195 Fixes for #1156, #1174, #1195 Feb 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support slnx solution format VB -> C#: VB With block conversion incorrect with null-conditional operator VB -> C#: ReDim Preserve of array property

1 participant