Skip to content

Commit bf6d6c0

Browse files
committed
Add regression test for issue #1091: interface DefaultMember Value access
When an interface or type has [DefaultMember("Value")] and VB code explicitly accesses .Value, the converter was incorrectly stripping the member access, producing `p` instead of `p.Value`. The fix (already in commit 924785a) adds `&& p.Parameters.Any()` to the `isDefaultProperty` check in ConvertMemberAccessExpressionAsync. This ensures only truly indexed (parameterized) default properties are stripped, while parameterless default members like Value retain their explicit access. This commit adds a regression test covering the exact scenario from issue #1091: an interface with <DefaultMember("Value")> where VB code explicitly reads and writes the .Value property. https://claude.ai/code/session_01AkwUvu3XuCdj3D4axoX4UX
1 parent 11a413a commit bf6d6c0

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

Tests/CSharp/MemberTests/DefaultMemberAttributeTests.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,45 @@ public void S()
4949
y.Caption = ""World"";
5050
}
5151
}
52+
");
53+
}
54+
55+
/// <summary>
56+
/// Regression test for https://github.com/icsharpcode/CodeConverter/issues/1091
57+
/// When an interface has [DefaultMember(""Value"")] and VB code explicitly accesses .Value,
58+
/// the converter must NOT strip the .Value member access in the C# output.
59+
/// </summary>
60+
[Fact]
61+
public async Task Issue1091_ExplicitAccessToDefaultMemberPropertyIsPreservedAsync()
62+
{
63+
await TestConversionVisualBasicToCSharpAsync(
64+
@"
65+
<System.Reflection.DefaultMember(""Value"")>
66+
Public Interface IWithDefaultValue
67+
Property Value As Object
68+
End Interface
69+
70+
Public Module Module1
71+
Sub Test(p As IWithDefaultValue)
72+
Dim v = p.Value
73+
p.Value = v
74+
End Sub
75+
End Module", @"using System.Reflection;
76+
77+
[DefaultMember(""Value"")]
78+
public partial interface IWithDefaultValue
79+
{
80+
object Value { get; set; }
81+
}
82+
83+
public static partial class Module1
84+
{
85+
public static void Test(IWithDefaultValue p)
86+
{
87+
var v = p.Value;
88+
p.Value = v;
89+
}
90+
}
5291
");
5392
}
5493
}

0 commit comments

Comments
 (0)