File tree Expand file tree Collapse file tree 3 files changed +10
-6
lines changed Expand file tree Collapse file tree 3 files changed +10
-6
lines changed Original file line number Diff line number Diff line change 1
- using Microsoft . CodeAnalysis . Text ;
1
+ using Microsoft . CodeAnalysis . CSharp . Syntax ;
2
+ using Microsoft . CodeAnalysis . Text ;
2
3
3
4
namespace ICSharpCode . CodeConverter . Common ;
4
5
@@ -7,7 +8,11 @@ public static SyntaxTree MakeFullCompilationUnit(this ILanguageConversion langua
7
8
var tree = languageConversion . CreateTree ( code ) ;
8
9
var root = tree . GetRoot ( ) ;
9
10
textSpan = null ;
10
- var rootChildren = root . ChildNodes ( ) . ToList ( ) ;
11
+
12
+ var rootChildren = root . ChildNodes ( )
13
+ //https://github.com/icsharpcode/CodeConverter/issues/825
14
+ . Select ( c => c is GlobalStatementSyntax { Statement : var s } ? s : c )
15
+ . ToList ( ) ;
11
16
var requiresSurroundingClass = rootChildren . Any ( languageConversion . MustBeContainedByClass ) ;
12
17
var requiresSurroundingMethod = rootChildren . All ( languageConversion . CanBeContainedByMethod ) ;
13
18
Original file line number Diff line number Diff line change @@ -148,14 +148,13 @@ public bool CanBeContainedByMethod(SyntaxNode node)
148
148
node is CSSyntax . StatementSyntax ||
149
149
node . ContainsSkippedText ||
150
150
node . IsMissing ||
151
- ParsedAsFieldButCouldBeLocalVariableDeclaration ( node ) ; ;
151
+ ParsedAsFieldButCouldBeLocalVariableDeclaration ( node ) ;
152
152
}
153
153
154
154
public bool MustBeContainedByClass ( SyntaxNode node )
155
155
{
156
156
return node is CSSyntax . BaseMethodDeclarationSyntax || node is CSSyntax . BaseFieldDeclarationSyntax ||
157
- node is CSSyntax . BasePropertyDeclarationSyntax ||
158
- node is CSSyntax . GlobalStatementSyntax ; //https://github.com/icsharpcode/CodeConverter/issues/825
157
+ node is CSSyntax . BasePropertyDeclarationSyntax ;
159
158
}
160
159
161
160
private static bool ParsedAsFieldButCouldBeLocalVariableDeclaration ( SyntaxNode node )
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ public async Task ReassignmentAsync()
12
12
await TestConversionCSharpToVisualBasicAsync (
13
13
@"int num = 4;
14
14
num = 5;" ,
15
- @"Dim num As Integer = 4
15
+ @"Dim num = 4
16
16
num = 5" ,
17
17
expectSurroundingMethodBlock : true ) ;
18
18
}
You can’t perform that action at this time.
0 commit comments