Commit dfe5298
Fix CS0206 when converting ReDim Preserve on a property
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>1 parent 1b5ac8e commit dfe5298
1 file changed
Lines changed: 10 additions & 8 deletions
Lines changed: 10 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
320 | 320 | | |
321 | 321 | | |
322 | 322 | | |
323 | | - | |
324 | | - | |
325 | | - | |
326 | | - | |
327 | | - | |
328 | | - | |
329 | | - | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
330 | 326 | | |
331 | | - | |
| 327 | + | |
332 | 328 | | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
333 | 335 | | |
334 | 336 | | |
335 | 337 | | |
| |||
0 commit comments