Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use TokenContext when creating modifiers for a DeclareStatementSyntax #1114

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion CodeConverter/CSharp/DeclarationNodeVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1504,7 +1504,13 @@ public override async Task<CSharpSyntaxNode> 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<TypeSyntax>(_triviaConvertingExpressionVisitor) ?? SyntaxFactory.PredefinedType(SyntaxFactory.Token(CSSyntaxKind.VoidKeyword));
var parameterListSyntax = await (node.ParameterList).AcceptAsync<ParameterListSyntax>(_triviaConvertingExpressionVisitor) ??
SyntaxFactory.ParameterList();
Expand Down
28 changes: 28 additions & 0 deletions Tests/CSharp/MemberTests/MemberTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
Loading