Fixes for #1156, #1174, #1195#1223
Open
GrahamTheCoder wants to merge 16 commits intoicsharpcode:masterfrom
Open
Fixes for #1156, #1174, #1195#1223GrahamTheCoder wants to merge 16 commits intoicsharpcode:masterfrom
GrahamTheCoder wants to merge 16 commits intoicsharpcode:masterfrom
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reintroduces support for dotnet 8 on the command line in case it helps: #1215