Skip to content

Commit 15eaf9c

Browse files
Apply to additional declarations - fixes #1053
Note: Also removed other changelog item which was broken and fixed within this release
1 parent 2d72880 commit 15eaf9c

3 files changed

Lines changed: 40 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
1010

1111
### VB -> C#
1212

13-
* Avoid stack overflow in stack overflow prevention code [#1047](https://github.com/icsharpcode/CodeConverter/issues/1047)
13+
* Ensure static declarations within property setters are converted [#1053](https://github.com/icsharpcode/CodeConverter/issues/1053)
1414
* Convert optional DateTime parameters [#1056](https://github.com/icsharpcode/CodeConverter/issues/1056)
1515
* Convert optional parameters before ref parameters using attributes to avoid compile error [#1057](https://github.com/icsharpcode/CodeConverter/issues/1057)
1616
* Remove square brackets when escaping labels and identifiers [#1043](https://github.com/icsharpcode/CodeConverter/issues/1043) and [#1044](https://github.com/icsharpcode/CodeConverter/issues/1044)

CodeConverter/CSharp/DeclarationNodeVisitor.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,10 @@ private async Task<IEnumerable<MemberDeclarationSyntax>> ConvertMembersAsync(VBS
221221
var convertedMembers = await members.SelectManyAsync(async member => {
222222
_typeContext.PerScopeState.PushScope();
223223
try {
224-
var convertedMember = (await ConvertMemberAsync(member)).Yield();
225-
var convertedPlusAdditional = (await _typeContext.PerScopeState.CreateVbStaticFieldsAsync(
224+
var convertedMember = (await ConvertMemberAsync(member)).Yield().Concat(GetAdditionalDeclarations(member));
225+
IEnumerable<MemberDeclarationSyntax> convertedPlusAdditional = (await _typeContext.PerScopeState.CreateVbStaticFieldsAsync(
226226
parentType, namedTypeSymbol, convertedMember, _generatedNames, _semanticModel)
227-
).Concat(GetAdditionalDeclarations(member));
227+
);
228228
return convertedPlusAdditional;
229229
}
230230
finally

Tests/CSharp/MemberTests/MemberTests.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,42 @@ public virtual int RenamedWriteOnlyProperty
608608
}");
609609
}
610610

611+
[Fact]
612+
public async Task SetterProperty1053Async()
613+
{
614+
await TestConversionVisualBasicToCSharpAsync(
615+
@"
616+
Public Property Prop(ByVal i As Integer) As String
617+
Get
618+
Static bGet As Boolean
619+
bGet = False
620+
End Get
621+
622+
Set(ByVal s As String)
623+
Static bSet As Boolean
624+
bSet = False
625+
End Set
626+
End Property
627+
", @"
628+
internal partial class SurroundingClass
629+
{
630+
private bool _Prop_bGet;
631+
private bool _Prop_bSet;
632+
633+
public string get_Prop(int i)
634+
{
635+
_Prop_bGet = false;
636+
return default;
637+
}
638+
639+
public void set_Prop(int i, string value)
640+
{
641+
_Prop_bSet = false;
642+
}
643+
644+
}", incompatibleWithAutomatedCommentTesting: true);// Known bug: Additional declarations don't get comments correctly converted
645+
}
646+
611647
[Fact]
612648
public async Task TestReadOnlyAndWriteOnlyParametrizedPropertyAsync()
613649
{

0 commit comments

Comments
 (0)