diff --git a/Src/Newtonsoft.Json/Linq/Extensions.cs b/Src/Newtonsoft.Json/Linq/Extensions.cs index f9f8976c..66381dcd 100644 --- a/Src/Newtonsoft.Json/Linq/Extensions.cs +++ b/Src/Newtonsoft.Json/Linq/Extensions.cs @@ -184,13 +184,14 @@ namespace Newtonsoft.Json.Linq { ValidationUtils.ArgumentNotNull(source, nameof(source)); - foreach (JToken token in source) + if (key == null) { - if (key == null) + foreach (T token in source) { - if (token is JValue) + JValue value = token as JValue; + if (value != null) { - yield return Convert((JValue)token); + yield return Convert(value); } else { @@ -200,7 +201,10 @@ namespace Newtonsoft.Json.Linq } } } - else + } + else + { + foreach (T token in source) { JToken value = token[key]; if (value != null) @@ -209,8 +213,6 @@ namespace Newtonsoft.Json.Linq } } } - - yield break; } //TODO