Skip to content

Commit fe73cc5

Browse files
Change the name to avoid #569
1 parent 268dbf2 commit fe73cc5

File tree

6 files changed

+37
-22
lines changed

6 files changed

+37
-22
lines changed

CodeConverter/CSharp/CommonConversions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ private static string WithDeclarationCasing(SyntaxToken id, ISymbol idSymbol, st
319319

320320
/// <remarks>
321321
/// Co-ordinates inlining property events, see <see cref="MethodBodyExecutableStatementVisitor.GetPostAssignmentStatements"/>
322+
/// Also see usages of IsDesignerGeneratedTypeWithInitializeComponent
322323
/// </remarks>
323324
public static bool MustInlinePropertyWithEventsAccess(SyntaxNode anyNodePossiblyWithinMethod, ISymbol potentialPropertySymbol)
324325
{

CodeConverter/CSharp/DeclarationNodeVisitor.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ private async Task<IEnumerable<MemberDeclarationSyntax>> ConvertMembersAsync(VBS
209209
var constructorFieldInitializersFromOtherParts = GetConstructorFieldInitializersFromOtherParts(namedTypeSymbol);
210210
additionalInitializers.AdditionalInstanceInitializers.AddRange(constructorFieldInitializersFromOtherParts);
211211
if (requiresInitializeComponent) {
212-
// Constructor event handlers not required since they'll be inside InitializeComponent
212+
// Constructor event handlers not required since they'll be inside InitializeComponent - see other use of IsDesignerGeneratedTypeWithInitializeComponent
213213
directlyConvertedMembers = directlyConvertedMembers.Concat(methodsWithHandles.CreateDelegatingMethodsRequiredByInitializeComponent());
214214
} else {
215215
additionalInitializers.AdditionalInstanceInitializers.AddRange(methodsWithHandles.GetConstructorEventHandlers());
@@ -929,6 +929,7 @@ public override async Task<CSharpSyntaxNode> VisitMethodBlock(VBSyntax.MethodBlo
929929
var visualBasicSyntaxVisitor = await CreateMethodBodyVisitorAsync(node, node.IsIterator(), csReturnVariableOrNull);
930930
var convertedStatements = await ConvertStatementsAsync(node.Statements, visualBasicSyntaxVisitor);
931931

932+
// Just class events - for property events, see other use of IsDesignerGeneratedTypeWithInitializeComponent
932933
if (node.SubOrFunctionStatement.Identifier.Text == "InitializeComponent" && node.SubOrFunctionStatement.IsKind(VBasic.SyntaxKind.SubStatement) && declaredSymbol.ContainingType.IsDesignerGeneratedTypeWithInitializeComponent(_vbCompilation)) {
933934
var firstResumeLayout = convertedStatements.Statements.FirstOrDefault(IsThisResumeLayoutInvocation) ?? convertedStatements.Statements.Last();
934935
convertedStatements = convertedStatements.InsertNodesBefore(firstResumeLayout, _typeContext.MethodsWithHandles.GetInitializeComponentClassEventHandlers());

CodeConverter/CSharp/ExpressionNodeVisitor.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,20 @@ public override async Task<CSharpSyntaxNode> VisitLiteralExpression(VBasic.Synta
272272
if (TypeConversionAnalyzer.ConvertStringToCharLiteral(node, typeInfo.Type, convertedType, out char chr)) {
273273
return CommonConversions.Literal(chr);
274274
}
275-
return CommonConversions.Literal(node.Token.Value, node.Token.Text, convertedType);
275+
276+
277+
var val = node.Token.Value;
278+
var text = node.Token.Text;
279+
if (node.Parent is VBSyntax.AssignmentStatementSyntax assignment && CommonConversions.InMethodCalledInitializeComponent(node.Parent) &&
280+
assignment.Left is VBSyntax.MemberAccessExpressionSyntax maes && !(maes.Expression is VBSyntax.MeExpressionSyntax) &&
281+
maes.Name.ToString() == "Name" &&
282+
val is string valStr) {
283+
// Update name so field is regenerated correctly by winforms designer
284+
val = "_" + valStr;
285+
text = "\"_" + valStr + "\"";
286+
}
287+
288+
return CommonConversions.Literal(val, text, convertedType);
276289
}
277290

278291
public override async Task<CSharpSyntaxNode> VisitInterpolation(VBasic.Syntax.InterpolationSyntax node)

Tests/CSharp/MemberTests/EventMemberTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ public void InitializeComponent()
533533
// POW_btnV2DBM
534534
//
535535
_POW_btnV2DBM.Location = new System.Drawing.Point(207, 15);
536-
_POW_btnV2DBM.Name = ""POW_btnV2DBM"";
536+
_POW_btnV2DBM.Name = ""_POW_btnV2DBM"";
537537
_POW_btnV2DBM.Size = new System.Drawing.Size(42, 23);
538538
_POW_btnV2DBM.TabIndex = 3;
539539
_POW_btnV2DBM.Text = "">>"";

Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/WindowsAppVb/Folder/FolderForm.Designer.cs

Lines changed: 16 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/WindowsAppVb/WinformsDesignerTest.Designer.cs

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)