Skip to content

Commit bdca73c

Browse files
committed
Fix double MyClass prefix when converting MyClass._Prop backing field access
When _Prop is accessed via MyClass._Prop, NameExpressionNodeVisitor.cs already adds the MyClass prefix via "$MyClass{ConvertIdentifier(...).ValueText}". The new ConvertIdentifier code was also returning MyClassProp for _Prop, causing a double prefix MyClassMyClassProp. Fix: detect when _Prop is part of a MyClass._Prop member access and return the bare property name so NameExpressionNodeVisitor can prefix it. https://claude.ai/code/session_01AkwUvu3XuCdj3D4axoX4UX
1 parent dc0596b commit bdca73c

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

CodeConverter/CSharp/CommonConversions.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,10 @@ public SyntaxToken ConvertIdentifier(SyntaxToken id, bool isAttribute = false, S
293293
// AND the first explicitly declared parameter is this symbol, we need to replace it with value.
294294
text = "value";
295295
} else if (normalizedText.StartsWith("_", StringComparison.OrdinalIgnoreCase) && idSymbol is IFieldSymbol propertyFieldSymbol && propertyFieldSymbol.AssociatedSymbol?.IsKind(SymbolKind.Property) == true) {
296-
// For virtual auto-properties, VB backing field _Prop maps to the C# MyClassProp backing property (bypasses virtual dispatch)
297-
text = propertyFieldSymbol.IsImplicitlyDeclared && propertyFieldSymbol.AssociatedSymbol is IPropertySymbol { IsVirtual: true, IsAbstract: false } vProp
296+
// For virtual auto-properties, VB backing field _Prop maps to the C# MyClassProp backing property (bypasses virtual dispatch).
297+
// Exception: when accessed as MyClass._Prop, NameExpressionNodeVisitor adds the "MyClass" prefix itself, so we just return the property name.
298+
var isAccessedViaMyClass = id.Parent?.Parent is VBSyntax.MemberAccessExpressionSyntax { Expression: VBSyntax.MyClassExpressionSyntax };
299+
text = !isAccessedViaMyClass && propertyFieldSymbol.IsImplicitlyDeclared && propertyFieldSymbol.AssociatedSymbol is IPropertySymbol { IsVirtual: true, IsAbstract: false } vProp
298300
? "MyClass" + vProp.Name
299301
: propertyFieldSymbol.AssociatedSymbol.Name;
300302
} else if (normalizedText.EndsWith("Event", StringComparison.OrdinalIgnoreCase) && idSymbol is IFieldSymbol eventFieldSymbol && eventFieldSymbol.AssociatedSymbol?.IsKind(SymbolKind.Event) == true) {

0 commit comments

Comments
 (0)