Skip to content

Commit

Permalink
Merge pull request #1335 from riganti/fix-property-group-clear
Browse files Browse the repository at this point in the history
Fix VirtualPropertyGroupDictionary.Clear
  • Loading branch information
exyi authored Mar 23, 2022
2 parents 1926b5e + aace4bb commit 81a22df
Showing 1 changed file with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -246,14 +246,32 @@ public void Add(KeyValuePair<string, TValue> item)

public void Clear()
{
// we want to avoid allocating the list if there is only one property
DotvvmProperty? toRemove = null;
List<DotvvmProperty>? toRemoveRest = null;

foreach (var (p, _) in control.properties)
{
var pg = p as GroupedDotvvmProperty;
if (pg != null && pg.PropertyGroup == group)
{
control.Properties.Remove(p);
if (toRemove is null)
toRemove = p;
else
{
if (toRemoveRest is null)
toRemoveRest = new List<DotvvmProperty>();
toRemoveRest.Add(p);
}
}
}

if (toRemove is {})
control.Properties.Remove(toRemove);

if (toRemoveRest is {})
foreach (var p in toRemoveRest)
control.Properties.Remove(p);
}

public bool Contains(KeyValuePair<string, TValue> item)
Expand Down

0 comments on commit 81a22df

Please sign in to comment.