Commit 5f8dd06 1 parent 248bd10 commit 5f8dd06 Copy full SHA for 5f8dd06
File tree 2 files changed +52
-0
lines changed
ICSharpCode.CodeConverter/CSharp
2 files changed +52
-0
lines changed Original file line number Diff line number Diff line change @@ -1041,6 +1041,9 @@ public override CSharpSyntaxNode VisitMemberAccessExpression(VBSyntax.MemberAcce
1041
1041
return SyntaxFactory . MemberBindingExpression ( simpleNameSyntax ) ;
1042
1042
}
1043
1043
left = SyntaxFactory . IdentifierName ( _withBlockTempVariableNames . Peek ( ) ) ;
1044
+ } else if ( TryGetTypePromotedModuleSymbol ( node , out var promotedModuleSymbol ) ) {
1045
+ left = SyntaxFactory . MemberAccessExpression ( SyntaxKind . SimpleMemberAccessExpression , left ,
1046
+ SyntaxFactory . IdentifierName ( promotedModuleSymbol . Name ) ) ;
1044
1047
}
1045
1048
1046
1049
if ( node . Expression . IsKind ( VBasic . SyntaxKind . GlobalName ) ) {
@@ -1056,6 +1059,22 @@ public override CSharpSyntaxNode VisitMemberAccessExpression(VBSyntax.MemberAcce
1056
1059
return memberAccessExpressionSyntax ;
1057
1060
}
1058
1061
1062
+ /// <remarks>https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features/declared-elements/type-promotion</remarks>
1063
+ private bool TryGetTypePromotedModuleSymbol ( VBSyntax . MemberAccessExpressionSyntax node , out INamedTypeSymbol moduleSymbol )
1064
+ {
1065
+ if ( _semanticModel . GetSymbolInfo ( node . Expression ) . ExtractBestMatch ( ) is INamespaceSymbol
1066
+ expressionSymbol &&
1067
+ _semanticModel . GetSymbolInfo ( node . Name ) . ExtractBestMatch ( ) . ContainingSymbol is INamedTypeSymbol
1068
+ nameContainingSymbol &&
1069
+ nameContainingSymbol . ContainingSymbol . Equals ( expressionSymbol ) ) {
1070
+ moduleSymbol = nameContainingSymbol ;
1071
+ return true ;
1072
+ }
1073
+
1074
+ moduleSymbol = null ;
1075
+ return false ;
1076
+ }
1077
+
1059
1078
private static bool IsSubPartOfConditionalAccess ( VBSyntax . MemberAccessExpressionSyntax node )
1060
1079
{
1061
1080
var firstPossiblyConditionalAncestor = node . Parent ;
Original file line number Diff line number Diff line change @@ -1169,6 +1169,39 @@ public void TestMethod(string dir)
1169
1169
}
1170
1170
}" ) ;
1171
1171
}
1172
+
1173
+ [ Fact ]
1174
+ public void TypePromotedModuleIsQualified ( )
1175
+ {
1176
+ TestConversionVisualBasicToCSharp ( @"Namespace TestNamespace
1177
+ Public Module TestModule
1178
+ Public Sub ModuleFunction()
1179
+ End Sub
1180
+ End Module
1181
+ End Namespace
1182
+
1183
+ Class TestClass
1184
+ Public Sub TestMethod(dir As String)
1185
+ TestNamespace.ModuleFunction()
1186
+ End Sub
1187
+ End Class" , @"namespace TestNamespace
1188
+ {
1189
+ public static class TestModule
1190
+ {
1191
+ public static void ModuleFunction()
1192
+ {
1193
+ }
1194
+ }
1195
+ }
1196
+
1197
+ class TestClass
1198
+ {
1199
+ public void TestMethod(string dir)
1200
+ {
1201
+ TestNamespace.TestModule.ModuleFunction();
1202
+ }
1203
+ }" ) ;
1204
+ }
1172
1205
1173
1206
[ Fact ]
1174
1207
public void NameQualifyingHandlesInheritance ( )
You can’t perform that action at this time.
0 commit comments