2 using System.Collections.Generic;
5 using Newtonsoft.Json.Utilities;
6 using System.Collections;
8 namespace Newtonsoft.Json.Linq
11 /// Represents a collection of <see cref="JToken"/> objects.
13 /// <typeparam name="T">The type of token</typeparam>
14 public struct JEnumerable<T> : IJEnumerable<T> where T : JToken
17 /// An empty collection of <see cref="JToken"/> objects.
19 public static readonly JEnumerable<T> Empty = new JEnumerable<T>(Enumerable.Empty<T>());
21 private IEnumerable<T> _enumerable;
24 /// Initializes a new instance of the <see cref="JEnumerable{T}"/> struct.
26 /// <param name="enumerable">The enumerable.</param>
27 public JEnumerable(IEnumerable<T> enumerable)
29 ValidationUtils.ArgumentNotNull(enumerable, "enumerable");
31 _enumerable = enumerable;
35 /// Returns an enumerator that iterates through the collection.
38 /// A <see cref="T:System.Collections.Generic.IEnumerator`1"/> that can be used to iterate through the collection.
40 public IEnumerator<T> GetEnumerator()
42 return _enumerable.GetEnumerator();
46 /// Returns an enumerator that iterates through a collection.
49 /// An <see cref="T:System.Collections.IEnumerator"/> object that can be used to iterate through the collection.
51 IEnumerator IEnumerable.GetEnumerator()
53 return GetEnumerator();
57 /// Gets the <see cref="IJEnumerable{JToken}"/> with the specified key.
60 public IJEnumerable<JToken> this[object key]
62 get { return new JEnumerable<JToken>(Extensions.Values<T, JToken>(_enumerable, key)); }
66 /// Determines whether the specified <see cref="System.Object"/> is equal to this instance.
68 /// <param name="obj">The <see cref="System.Object"/> to compare with this instance.</param>
70 /// <c>true</c> if the specified <see cref="System.Object"/> is equal to this instance; otherwise, <c>false</c>.
72 public override bool Equals(object obj)
74 if (obj is JEnumerable<T>)
75 return _enumerable.Equals(((JEnumerable<T>)obj)._enumerable);
81 /// Returns a hash code for this instance.
84 /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
86 public override int GetHashCode()
88 return _enumerable.GetHashCode();