Skip to content
This repository was archived by the owner on Apr 28, 2020. It is now read-only.

Commit f5f5abb

Browse files
mcraihajordanbtucker
authored andcommitted
Make KeysTest work better
C# does not allow modifications for collections while they are iterated, so get copy of keys and run with that. There is now special case for top level holdering ("" as key), otherwise transformer is also executed for it (yes, this is ugly and needs fixing).
1 parent fbebe4d commit f5f5abb

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

Json5/Json5.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ private static Json5Value Walk(Json5Container holder, string key, Func<Json5Cont
105105
if (value is Json5Container)
106106
{
107107
Json5Container c = (Json5Container)value;
108-
foreach (string k in c.Keys)
108+
string[] keys = c.Keys.ToArray();
109+
foreach (string k in keys)
109110
{
110111
Json5Value v = Walk(c, k, transformer);
111112
if (v != null)
@@ -115,6 +116,12 @@ private static Json5Value Walk(Json5Container holder, string key, Func<Json5Cont
115116
}
116117
}
117118

119+
// Special case for holder
120+
if (key == "")
121+
{
122+
return value;
123+
}
124+
118125
return transformer(holder, key, value);
119126
}
120127

0 commit comments

Comments
 (0)