Skip to content

Commit

Permalink
Ensure class constructors are marked as public [icsharpcode#422]
Browse files Browse the repository at this point in the history
  • Loading branch information
mrmonday committed Nov 15, 2019
1 parent 0904218 commit 0d1952c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -20,6 +20,7 @@ All notable changes to the code converter will be documented here.
* Correctly handle type promoted module symbols (#375)
* Prefer renamed imports for name resolution (#401)
* Correctly convert ambiguous names (#332)
* Ensure correct visibility for constructors (#422)

### C# -> VB
* Convert property accessors with visiblity modifiers (#92)
Expand Down
2 changes: 1 addition & 1 deletion ICSharpCode.CodeConverter/CSharp/CommonConversions.cs
Expand Up @@ -265,7 +265,7 @@ private static SyntaxToken CsEscapedIdentifier(string text)
var declaredAccessibility = declaredSymbol?.DeclaredAccessibility ?? Accessibility.NotApplicable;

var contextsWithIdenticalDefaults = new[] { TokenContext.Global, TokenContext.Local, TokenContext.InterfaceOrModule, TokenContext.MemberInInterface };
bool isPartial = declaredSymbol.IsPartialClassDefinition() || declaredSymbol.IsPartialMethodDefinition() || declaredSymbol.IsPartialMethodImplementation();
bool isPartial = declaredSymbol.IsPartialClassDefinition() || declaredSymbol.IsPartialMethodDefinition() || declaredSymbol.IsPartialMethodImplementation() || declaredSymbol.IsConstructor();
bool implicitVisibility = contextsWithIdenticalDefaults.Contains(context) || isVariableOrConst || isConstructor;
if (implicitVisibility && !isPartial) declaredAccessibility = Accessibility.NotApplicable;
var modifierSyntaxs = ConvertModifiersCore(declaredAccessibility, modifiers, context)
Expand Down
2 changes: 1 addition & 1 deletion Tests/CSharp/ExpressionTests.cs
Expand Up @@ -977,7 +977,7 @@ End Get
End Property
End Class", @"public partial class Class1
{
Class1()
public Class1()
{
var needsInitialization = default(int);
int notUsed;
Expand Down
16 changes: 15 additions & 1 deletion Tests/CSharp/MemberTests.cs
Expand Up @@ -36,6 +36,20 @@ public async Task TestConstantFieldInModule()
}");
}

[Fact]
public async Task TestConstructorVisibility()
{
await TestConversionVisualBasicToCSharpWithoutComments(@"Class Class1
Sub New(x As Boolean)
End Sub
End Class", @"internal partial class Class1
{
public Class1(bool x)
{
}
}");
}

[Fact]
public async Task TestModuleConstructor()
{
Expand Down Expand Up @@ -779,7 +793,7 @@ public async Task TestConstructorWithImplicitPublicAccessibility()
{
await TestConversionVisualBasicToCSharp(
@"Sub New()
End Sub", @"SurroundingClass()
End Sub", @"public SurroundingClass()
{
}");
}
Expand Down

0 comments on commit 0d1952c

Please sign in to comment.