Skip to content

Commit 75ff80c

Browse files
authored
Add do...while loop in the SetValue method of SerializationResourceManager.cs until resourceName is unique (#13578)
* Add do...while loop in the SetValue method of SerializationResourceManager.cs until resourceName is unique * Check nameBase directly rather than resourceName for clarity
1 parent 847c2a4 commit 75ff80c

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/System.Windows.Forms.Design/src/System/ComponentModel/Design/Serialization/ResourceCodeDomSerializer.SerializationResourceManager.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -778,10 +778,17 @@ public string SetValue(IDesignerSerializationManager manager, ExpressionContext?
778778

779779
// Only append the number when appendCount is set or if there is already a count.
780780
int count = 0;
781-
if (appendCount || _nameTable.TryGetValue(nameBase, out count))
781+
782+
if (appendCount || _nameTable.ContainsKey(nameBase))
782783
{
783-
count++;
784-
resourceName = $"{nameBase}{count}";
784+
_nameTable.TryGetValue(nameBase, out count);
785+
786+
do
787+
{
788+
count++;
789+
resourceName = $"{nameBase}{count}";
790+
}
791+
while (_nameTable.ContainsKey(resourceName));
785792
}
786793

787794
// Now that we have a name, write out the resource.

0 commit comments

Comments
 (0)