Пример #1
0
 protected T GetEnumeratorHelper <T>(Func <T> getEnumerator) where T : IEnumerator
 {
     if (getEnumerator == null)
     {
         throw new ArgumentNullException("getEnumerator");
     }
     if (this.Results.Context != null)
     {
         bool?singleResult = this.Query.QueryComponents(this.Results.Context.MaxProtocolVersion).SingleResult;
         if (singleResult.HasValue && !singleResult.Value)
         {
             IEnumerator enumerator = this.Results.GetEnumerator();
             if (enumerator.MoveNext())
             {
                 object      current = enumerator.Current;
                 ICollection is2     = current as ICollection;
                 if (is2 == null)
                 {
                     throw new DataServiceClientException(Strings.AtomMaterializer_CollectionExpectedCollection(current.GetType().ToString()));
                 }
                 return((T)is2.GetEnumerator());
             }
         }
     }
     return(getEnumerator());
 }
Пример #2
0
        /// <summary>Gets the enumeration helper for the <see cref="T:System.Data.Services.Client.QueryOperationResponse" />.</summary>
        /// <param name="getEnumerator">The enumerator.</param>
        /// <typeparam name="T">The generic type.</typeparam>
        /// <returns>An enumerator to enumerator through the results.</returns>
        protected T GetEnumeratorHelper <T>(Func <T> getEnumerator) where T : IEnumerator
        {
            if (getEnumerator == null)
            {
                throw new ArgumentNullException("getEnumerator");
            }

            if (this.Results.Context != null)
            {
                bool?singleResult = this.Query.QueryComponents(this.Results.Context.Model).SingleResult;

                if (singleResult.HasValue && !singleResult.Value)
                {
                    // Case: collection of complex or primitive.
                    // We materialize the entire collection now, and give them the inner enumerator instead
                    IEnumerator enumerator = this.Results.GetEnumerator();
                    if (enumerator.MoveNext())
                    {
                        object      innerObject            = enumerator.Current;
                        ICollection materializedCollection = innerObject as ICollection;

                        if (materializedCollection == null)
                        {
                            throw new DataServiceClientException(Strings.AtomMaterializer_CollectionExpectedCollection(innerObject.GetType().ToString()));
                        }

                        Debug.Assert(!enumerator.MoveNext(), "MaterializationEvents of top level collection expected one result of ICollection<>, but found at least 2 results");
                        return((T)materializedCollection.GetEnumerator());
                    }
                    else
                    {
                        Debug.Assert(false, "MaterializationEvents of top level collection expected one result of ICollection<>, but found at least no results.");
                    }
                }
            }

            return(getEnumerator());
        }