internal static IEnumerable <U> Values <T, U>(this IEnumerable <T> source, object key) where T : JToken { ValidationUtils.ArgumentNotNull(source, nameof(source)); foreach (JToken token in source) { if (key == null) { if (token is JValue) { yield return(Convert <JValue, U>((JValue)token)); } else { foreach (JToken t in token.Children()) { yield return(t.Convert <JToken, U>()); } } } else { JToken value = token[key]; if (value != null) { yield return(value.Convert <JToken, U>()); } } } yield break; }
/// <summary> /// Converts the value. /// </summary> /// <typeparam name="T">The source collection type.</typeparam> /// <typeparam name="U">The type to convert the value to.</typeparam> /// <param name="value">A <see cref="JToken"/> cast as a <see cref="IEnumerable{T}"/> of <see cref="JToken"/>.</param> /// <returns>A converted value.</returns> public static U Value <T, U>(this IEnumerable <T> value) where T : JToken { ValidationUtils.ArgumentNotNull(value, nameof(value)); JToken token = value as JToken; if (token == null) { throw new ArgumentException("Source value must be a JToken."); } return(token.Convert <JToken, U>()); }