diff --git a/CodeConverter/CSharp/DeclarationNodeVisitor.cs b/CodeConverter/CSharp/DeclarationNodeVisitor.cs index 0030f880..69819066 100644 --- a/CodeConverter/CSharp/DeclarationNodeVisitor.cs +++ b/CodeConverter/CSharp/DeclarationNodeVisitor.cs @@ -1504,7 +1504,13 @@ public override async Task VisitDeclareStatement(VBSyntax.Decl var attributeLists = (await CommonConversions.ConvertAttributesAsync(node.AttributeLists)).Add(dllImportAttributeList); - var modifiers = CommonConversions.ConvertModifiers(node, node.Modifiers).Add(SyntaxFactory.Token(CSSyntaxKind.StaticKeyword)).Add(SyntaxFactory.Token(CSSyntaxKind.ExternKeyword)); + var tokenContext = GetMemberContext(node); + var modifiers = CommonConversions.ConvertModifiers(node, node.Modifiers, tokenContext); + if (!modifiers.Any(m => m.IsKind(CSSyntaxKind.StaticKeyword))) { + modifiers = modifiers.Add(SyntaxFactory.Token(CSSyntaxKind.StaticKeyword)); + } + modifiers = modifiers.Add(SyntaxFactory.Token(CSSyntaxKind.ExternKeyword)); + var returnType = await (node.AsClause?.Type).AcceptAsync(_triviaConvertingExpressionVisitor) ?? SyntaxFactory.PredefinedType(SyntaxFactory.Token(CSSyntaxKind.VoidKeyword)); var parameterListSyntax = await (node.ParameterList).AcceptAsync(_triviaConvertingExpressionVisitor) ?? SyntaxFactory.ParameterList(); diff --git a/Tests/CSharp/MemberTests/MemberTests.cs b/Tests/CSharp/MemberTests/MemberTests.cs index af4fb542..148aa6a5 100644 --- a/Tests/CSharp/MemberTests/MemberTests.cs +++ b/Tests/CSharp/MemberTests/MemberTests.cs @@ -84,6 +84,34 @@ static Module1() }"); } + [Fact] + public async Task TestDeclareMethodVisibilityInModuleAsync() + { + await TestConversionVisualBasicToCSharpAsync(@"Module Module1 + Declare Sub External Lib ""lib.dll"" () +End Module", @"using System.Runtime.InteropServices; + +internal static partial class Module1 +{ + [DllImport(""lib.dll"")] + public static extern void External(); +}"); + } + + [Fact] + public async Task TestDeclareMethodVisibilityInClassAsync() + { + await TestConversionVisualBasicToCSharpAsync(@"Class Class1 + Declare Sub External Lib ""lib.dll"" () +End Class", @"using System.Runtime.InteropServices; + +internal partial class Class1 +{ + [DllImport(""lib.dll"")] + public static extern void External(); +}"); + } + [Fact] public async Task TestTypeInferredConstAsync() {