Skip to content

Commit ce8fb50

Browse files
author
tznind
committed
Use iterative calls to Add instead of Menus setter
1 parent 7f3e6ff commit ce8fb50

1 file changed

Lines changed: 8 additions & 14 deletions

File tree

src/ToCode/MenuBarItemsToCode.cs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,15 @@ public void ToCode(CodeDomArgs args)
5656
{
5757
this.ToCode(args, child, out string fieldName);
5858
menus.Add(fieldName);
59-
}
6059

61-
this.AddPropertyAssignment(
62-
args,
63-
$"this.{this.design.FieldName}.{nameof(this.menuBar.Menus)}",
64-
new CodeArrayCreateExpression(
65-
typeof(MenuBarItem),
66-
menus.Select(c =>
67-
new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), c))
68-
.ToArray()));
69-
60+
this.AddMethodCall(args,
61+
new CodeFieldReferenceExpression(
62+
new CodeThisReferenceExpression(), this.design.FieldName),
63+
"Add",
64+
// or the name of the field for each menu item
65+
new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), fieldName)
66+
);
67+
}
7068
}
7169

7270
private void ToCode(CodeDomArgs args, MenuBarItem child, out string fieldName)
@@ -119,11 +117,7 @@ private void ToCode(CodeDomArgs args, MenuBarItem child, out string fieldName)
119117

120118
foreach(var c in children)
121119
{
122-
123-
// we have created fields and constructor calls for our menu
124-
// now set the menu to an array of all those fields
125120
this.AddMethodCall(args,
126-
127121
new CodeFieldReferenceExpression(
128122
new CodeThisReferenceExpression(), fieldName),
129123
"Add",

0 commit comments

Comments
 (0)