Esempio n. 1
0
 internal static IEnumerable <U> Values <T, U>(this IEnumerable <T> source, object key) where T : JToken
 {
     ValidationUtils.ArgumentNotNull((object)source, "source");
     foreach (T obj in source)
     {
         JToken token = (JToken)obj;
         if (key == null)
         {
             if (token is JValue)
             {
                 yield return(Extensions.Convert <JValue, U>((JValue)token));
             }
             else
             {
                 foreach (JToken token1 in token.Children())
                 {
                     yield return(Extensions.Convert <JToken, U>(token1));
                 }
             }
         }
         else
         {
             JToken value = token[key];
             if (value != null)
             {
                 yield return(Extensions.Convert <JToken, U>(value));
             }
         }
     }
 }
Esempio n. 2
0
 internal static IEnumerable <U> Convert <T, U>(this IEnumerable <T> source) where T : JToken
 {
     ValidationUtils.ArgumentNotNull((object)source, "source");
     foreach (T obj in source)
     {
         yield return(Extensions.Convert <JToken, U>((JToken)obj));
     }
 }
Esempio n. 3
0
        public static U Value <T, U>(this IEnumerable <T> value) where T : JToken
        {
            ValidationUtils.ArgumentNotNull((object)value, "source");
            JToken token = value as JToken;

            if (token == null)
            {
                throw new ArgumentException("Source value must be a JToken.");
            }
            else
            {
                return(Extensions.Convert <JToken, U>(token));
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Gets the <see cref="JToken"/> with the specified key converted to the specified type.
        /// </summary>
        /// <typeparam name="T">The type to convert the token to.</typeparam>
        /// <param name="key">The token key.</param>
        /// <returns>The converted token value.</returns>
        public virtual T Value <T>(object key)
        {
            JToken token = this[key];

            return(Extensions.Convert <JToken, T>(token));
        }
Esempio n. 5
0
 public static IEnumerable <U> Children <T, U>(this IEnumerable <T> source) where T : JToken
 {
     ValidationUtils.ArgumentNotNull((object)source, "source");
     return(Extensions.Convert <JToken, U>(Enumerable.SelectMany <T, JToken>(source, (Func <T, IEnumerable <JToken> >)(c => (IEnumerable <JToken>)c.Children()))));
 }
Esempio n. 6
0
 public virtual T Value <T>(object key)
 {
     return(Extensions.Convert <JToken, T>(this[key]));
 }
Esempio n. 7
0
 public override IEnumerable <T> Values <T>()
 {
     return(Extensions.Convert <JToken, T>((IEnumerable <JToken>) this.ChildrenTokens));
 }