using System; using System.Collections.Generic; using System.Linq; using System.Text; using Newtonsoft.Json.Utilities; using System.Collections; namespace Newtonsoft.Json.Linq { /// /// Represents a collection of objects. /// /// The type of token public struct JEnumerable : IJEnumerable where T : JToken { /// /// An empty collection of objects. /// public static readonly JEnumerable Empty = new JEnumerable(Enumerable.Empty()); private IEnumerable _enumerable; /// /// Initializes a new instance of the struct. /// /// The enumerable. public JEnumerable(IEnumerable enumerable) { ValidationUtils.ArgumentNotNull(enumerable, "enumerable"); _enumerable = enumerable; } /// /// Returns an enumerator that iterates through the collection. /// /// /// A that can be used to iterate through the collection. /// public IEnumerator GetEnumerator() { return _enumerable.GetEnumerator(); } /// /// Returns an enumerator that iterates through a collection. /// /// /// An object that can be used to iterate through the collection. /// IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } /// /// Gets the with the specified key. /// /// public IJEnumerable this[object key] { get { return new JEnumerable(Extensions.Values(_enumerable, key)); } } /// /// Determines whether the specified is equal to this instance. /// /// The to compare with this instance. /// /// true if the specified is equal to this instance; otherwise, false. /// public override bool Equals(object obj) { if (obj is JEnumerable) return _enumerable.Equals(((JEnumerable)obj)._enumerable); return false; } /// /// Returns a hash code for this instance. /// /// /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. /// public override int GetHashCode() { return _enumerable.GetHashCode(); } } }