/// <summary>
        /// Applies the values of a nested <paramref name="feed"/> to the collection
        /// <paramref name="property"/> of the specified <paramref name="entry"/>.
        /// </summary>
        /// <param name="entry">Entry with collection to be modified.</param>
        /// <param name="property">Collection property on the entry.</param>
        /// <param name="feed">Values to apply onto the collection.</param>
        /// <param name="includeLinks">Whether links that are expanded should be materialized.</param>
        private void ApplyFeedToCollection(
            MaterializerEntry entry,
            ClientPropertyAnnotation property,
            ODataFeed feed,
            bool includeLinks)
        {
            Debug.Assert(entry.Entry != null, "entry != null");
            Debug.Assert(property != null, "property != null");
            Debug.Assert(feed != null, "feed != null");

            ClientEdmModel       edmModel       = this.MaterializerContext.Model;
            ClientTypeAnnotation collectionType = edmModel.GetClientTypeAnnotation(edmModel.GetOrCreateEdmType(property.EntityCollectionItemType));

            IEnumerable <ODataEntry> entries = MaterializerFeed.GetFeed(feed).Entries;

            foreach (ODataEntry feedEntry in entries)
            {
                this.Materialize(MaterializerEntry.GetEntry(feedEntry), collectionType.ElementType, includeLinks);
            }

            ProjectionPlan continuationPlan = includeLinks ?
                                              ODataEntityMaterializer.CreatePlanForDirectMaterialization(property.EntityCollectionItemType) :
                                              ODataEntityMaterializer.CreatePlanForShallowMaterialization(property.EntityCollectionItemType);

            this.ApplyItemsToCollection(
                entry,
                property,
                entries.Select(e => MaterializerEntry.GetEntry(e).ResolvedObject),
                feed.NextPageLink,
                continuationPlan,
                false);
        }
Exemplo n.º 2
0
        internal static List <TTarget> ListAsElementType <T, TTarget>(ODataEntityMaterializer materializer, IEnumerable <T> source) where T : TTarget
        {
            List <TTarget> list2;
            DataServiceQueryContinuation continuation;
            List <TTarget> list = source as List <TTarget>;

            if (list != null)
            {
                return(list);
            }
            IList list3 = source as IList;

            if (list3 != null)
            {
                list2 = new List <TTarget>(list3.Count);
            }
            else
            {
                list2 = new List <TTarget>();
            }
            foreach (T local in source)
            {
                list2.Add((TTarget)local);
            }
            if (materializer.nextLinkTable.TryGetValue(source, out continuation))
            {
                materializer.nextLinkTable[list2] = continuation;
            }
            return(list2);
        }
Exemplo n.º 3
0
        internal static object ProjectionInitializeEntity(ODataEntityMaterializer materializer, MaterializerEntry entry, Type expectedType, Type resultType, string[] properties, Func <object, object, Type, object>[] propertyValues)
        {
            if (entry.Entry == null)
            {
                throw new NullReferenceException(System.Data.Services.Client.Strings.AtomMaterializer_EntryToInitializeIsNull(resultType.FullName));
            }
            if (!entry.EntityHasBeenResolved)
            {
                ProjectionEnsureEntryAvailableOfType(materializer, entry, resultType);
            }
            else if (!resultType.IsAssignableFrom(entry.ActualType.ElementType))
            {
                throw new InvalidOperationException(System.Data.Services.Client.Strings.AtomMaterializer_ProjectEntityTypeMismatch(resultType.FullName, entry.ActualType.ElementType.FullName, entry.Entry.Id));
            }
            object resolvedObject = entry.ResolvedObject;

            for (int i = 0; i < properties.Length; i++)
            {
                StreamDescriptor         descriptor;
                string                   propertyName = properties[i];
                ClientPropertyAnnotation annotation   = entry.ActualType.GetProperty(propertyName, materializer.ResponseInfo.IgnoreMissingProperties);
                object                   target       = propertyValues[i](materializer, entry.Entry, expectedType);
                ODataProperty            property     = (from p in entry.Entry.Properties
                                                         where p.Name == propertyName
                                                         select p).FirstOrDefault <ODataProperty>();
                if ((((((property == null) && (entry.NavigationLinks != null)) ? (from l in entry.NavigationLinks
                                                                                  where l.Name == propertyName
                                                                                  select l).FirstOrDefault <ODataNavigationLink>() : null) != null) || (property != null)) || entry.EntityDescriptor.TryGetNamedStreamInfo(propertyName, out descriptor))
                {
                    if (entry.ShouldUpdateFromPayload && (annotation.EdmProperty.Type.TypeKind() == EdmTypeKind.Entity))
                    {
                        materializer.Log.SetLink(entry, annotation.PropertyName, target);
                    }
                    if (entry.ShouldUpdateFromPayload)
                    {
                        if (!annotation.IsEntityCollection)
                        {
                            if (!annotation.IsPrimitiveOrComplexCollection)
                            {
                                annotation.SetValue(resolvedObject, target, annotation.PropertyName, false);
                            }
                        }
                        else
                        {
                            IEnumerable list = (IEnumerable)target;
                            DataServiceQueryContinuation continuation = materializer.nextLinkTable[list];
                            Uri            nextLink = (continuation == null) ? null : continuation.NextLinkUri;
                            ProjectionPlan plan     = (continuation == null) ? null : continuation.Plan;
                            materializer.MergeLists(entry, annotation, list, nextLink, plan);
                        }
                    }
                    else if (annotation.IsEntityCollection)
                    {
                        materializer.FoundNextLinkForUnmodifiedCollection(annotation.GetValue(entry.ResolvedObject) as IEnumerable);
                    }
                }
            }
            return(resolvedObject);
        }
Exemplo n.º 4
0
 /// <summary>Checks whether the entity on the specified <paramref name="path"/> is null.</summary>
 /// <param name="entry">Root entry for paths.</param>
 /// <param name="expectedType">Expected type for <paramref name="entry"/>.</param>
 /// <param name="path">Path to pull value for.</param>
 /// <returns>Whether the specified <paramref name="path"/> is null.</returns>
 /// <remarks>
 /// This method will not instantiate entity types on the path.
 /// </remarks>
 internal static bool ProjectionCheckValueForPathIsNull(
     object entry,
     Type expectedType,
     object path)
 {
     Debug.Assert(entry.GetType() == typeof(ODataEntry), "entry.GetType() == typeof(ODataEntry)");
     Debug.Assert(path.GetType() == typeof(ProjectionPath), "path.GetType() == typeof(ProjectionPath)");
     return(ODataEntityMaterializer.ProjectionCheckValueForPathIsNull(MaterializerEntry.GetEntry((ODataEntry)entry), expectedType, (ProjectionPath)path));
 }
Exemplo n.º 5
0
        /// <summary>Initializes a projection-driven entry (with a specific type and specific properties).</summary>
        /// <param name="materializer">Materializer under which projection is taking place.</param>
        /// <param name="entry">Root entry for paths.</param>
        /// <param name="expectedType">Expected type for <paramref name="entry"/>.</param>
        /// <param name="resultType">Expected result type.</param>
        /// <param name="properties">Properties to materialize.</param>
        /// <param name="propertyValues">Functions to get values for functions.</param>
        /// <returns>The initialized entry.</returns>
        internal static object ProjectionInitializeEntity(
            object materializer,
            object entry,
            Type expectedType,
            Type resultType,
            string[] properties,
            Func <object, object, Type, object>[] propertyValues)
        {
            Debug.Assert(typeof(ODataEntityMaterializer).IsAssignableFrom(materializer.GetType()), "typeof(ODataEntityMaterializer).IsAssignableFrom(materializer.GetType())");
            Debug.Assert(((ODataEntityMaterializer)materializer).MaterializerContext.AutoNullPropagation || entry is ODataEntry, "((ODataEntityMaterializer)materializer).MaterializerContext.AutoNullPropagation || entry is ODataEntry");

            return(ODataEntityMaterializer.ProjectionInitializeEntity((ODataEntityMaterializer)materializer, MaterializerEntry.GetEntry((ODataEntry)entry), expectedType, resultType, properties, propertyValues));
        }
Exemplo n.º 6
0
 /// <summary>Provides support for Select invocations for projections.</summary>
 /// <param name="materializer">Materializer under which projection is taking place.</param>
 /// <param name="entry">Root entry for paths.</param>
 /// <param name="expectedType">Expected type for <paramref name="entry"/>.</param>
 /// <param name="resultType">Expected result type.</param>
 /// <param name="path">Path to traverse.</param>
 /// <param name="selector">Selector callback.</param>
 /// <returns>An enumerable with the select results.</returns>
 internal static IEnumerable ProjectionSelect(
     object materializer,
     object entry,
     Type expectedType,
     Type resultType,
     object path,
     Func <object, object, Type, object> selector)
 {
     Debug.Assert(typeof(ODataEntityMaterializer).IsAssignableFrom(materializer.GetType()), "typeof(ODataEntityMaterializer).IsAssignableFrom(materializer.GetType())");
     Debug.Assert(entry.GetType() == typeof(ODataEntry), "entry.GetType() == typeof(ODataEntry)");
     Debug.Assert(path.GetType() == typeof(ProjectionPath), "path.GetType() == typeof(ProjectionPath)");
     return(ODataEntityMaterializer.ProjectionSelect((ODataEntityMaterializer)materializer, MaterializerEntry.GetEntry((ODataEntry)entry), expectedType, resultType, (ProjectionPath)path, selector));
 }
Exemplo n.º 7
0
        private static void MaterializeToList(ODataEntityMaterializer materializer, IEnumerable list, Type nestedExpectedType, IEnumerable <ODataEntry> entries)
        {
            Action <object, object> addToCollectionDelegate = ODataMaterializer.GetAddToCollectionDelegate(list.GetType());

            foreach (ODataEntry entry in entries)
            {
                MaterializerEntry entry2 = MaterializerEntry.GetEntry(entry);
                if (!entry2.EntityHasBeenResolved)
                {
                    materializer.Materialize(entry2, nestedExpectedType, false);
                }
                addToCollectionDelegate(list, entry2.ResolvedObject);
            }
        }
Exemplo n.º 8
0
 internal static void ProjectionEnsureEntryAvailableOfType(ODataEntityMaterializer materializer, MaterializerEntry entry, Type requiredType)
 {
     if (entry.Id == null)
     {
         throw System.Data.Services.Client.Error.InvalidOperation(System.Data.Services.Client.Strings.Deserialize_MissingIdElement);
     }
     if (!materializer.TryResolveAsCreated(entry) && !materializer.TryResolveFromContext(entry, requiredType))
     {
         materializer.ResolveByCreatingWithType(entry, requiredType);
     }
     else if (!requiredType.IsAssignableFrom(entry.ResolvedObject.GetType()))
     {
         throw System.Data.Services.Client.Error.InvalidOperation(System.Data.Services.Client.Strings.Deserialize_Current(requiredType, entry.ResolvedObject.GetType()));
     }
 }
Exemplo n.º 9
0
        internal static IEnumerable ProjectionSelect(ODataEntityMaterializer materializer, MaterializerEntry entry, Type expectedType, Type resultType, ProjectionPath path, Func <object, object, Type, object> selector)
        {
            ClientEdmModel             model = ClientEdmModel.GetModel(materializer.ResponseInfo.MaxProtocolVersion);
            ClientTypeAnnotation       clientTypeAnnotation = entry.ActualType ?? model.GetClientTypeAnnotation(model.GetOrCreateEdmType(expectedType));
            IEnumerable                enumerable           = (IEnumerable)Util.ActivatorCreateInstance(typeof(List <>).MakeGenericType(new Type[] { resultType }), new object[0]);
            MaterializerNavigationLink link     = null;
            ClientPropertyAnnotation   property = null;

            for (int i = 0; i < path.Count; i++)
            {
                ProjectionPathSegment segment = path[i];
                if (segment.SourceTypeAs != null)
                {
                    clientTypeAnnotation = model.GetClientTypeAnnotation(model.GetOrCreateEdmType(segment.SourceTypeAs));
                }
                if (segment.Member != null)
                {
                    string member = segment.Member;
                    property = clientTypeAnnotation.GetProperty(member, false);
                    link     = GetPropertyOrThrow(entry.NavigationLinks, member, entry.Id);
                    if (link.Entry != null)
                    {
                        entry = link.Entry;
                        clientTypeAnnotation = model.GetClientTypeAnnotation(model.GetOrCreateEdmType(property.PropertyType));
                    }
                }
            }
            ValidatePropertyMatch(property, link.Link);
            MaterializerFeed        feed = MaterializerFeed.GetFeed(link.Feed);
            Action <object, object> addToCollectionDelegate = ODataMaterializer.GetAddToCollectionDelegate(enumerable.GetType());

            foreach (ODataEntry entry2 in feed.Entries)
            {
                object obj2 = selector(materializer, entry2, property.EntityCollectionItemType);
                addToCollectionDelegate(enumerable, obj2);
            }
            ProjectionPlan plan = new ProjectionPlan {
                LastSegmentType = property.EntityCollectionItemType,
                Plan            = selector,
                ProjectedType   = resultType
            };

            materializer.FoundNextLinkForCollection(enumerable, feed.NextPageLink, plan);
            return(enumerable);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Applies the values of the <paramref name="items"/> enumeration to the
        /// <paramref name="property"/> of the specified <paramref name="entry"/>.
        /// </summary>
        /// <param name="entry">Entry with collection to be modified.</param>
        /// <param name="property">Collection property on the entry.</param>
        /// <param name="items">Values to apply onto the collection.</param>
        /// <param name="nextLink">Next link for collection continuation.</param>
        /// <param name="continuationPlan">Projection plan for collection continuation.</param>
        /// <param name="isContinuation">Whether this is a continuation request.</param>
        internal void ApplyItemsToCollection(
            MaterializerEntry entry,
            ClientPropertyAnnotation property,
            IEnumerable items,
            Uri nextLink,
            ProjectionPlan continuationPlan,
            bool isContinuation)
        {
            Debug.Assert(entry.Entry != null || entry.ForLoadProperty, "ODataEntry should be non-null except for LoadProperty");
            Debug.Assert(property != null, "property != null");
            Debug.Assert(items != null, "items != null");

            IEnumerable <object> itemsEnumerable = ODataEntityMaterializer.EnumerateAsElementType <object>(items);

            // Populate the collection property with items collection.
            object collection = this.PopulateCollectionProperty(entry, property, itemsEnumerable, nextLink, continuationPlan);

            // Get collection of all non-linked elements in collection and remove them except for the ones that were obtained from the response.
            if (this.EntityTrackingAdapter.MergeOption == MergeOption.OverwriteChanges ||
                this.EntityTrackingAdapter.MergeOption == MergeOption.PreserveChanges)
            {
                var linkedItemsInCollection =
                    this.EntityTrackingAdapter
                    .EntityTracker
                    .GetLinks(entry.ResolvedObject, property.PropertyName)
                    .Select(l => new { l.Target, l.IsModified });

                if (collection != null && !property.IsDictionary)
                {
                    var nonLinkedNonReceivedItemsInCollection = ODataEntityMaterializer.EnumerateAsElementType <object>((IEnumerable)collection)
                                                                .Except(linkedItemsInCollection.Select(i => i.Target))
                                                                .Except(itemsEnumerable).ToArray();

                    // Since no link exists, we just remove the item from the collection
                    foreach (var item in nonLinkedNonReceivedItemsInCollection)
                    {
                        property.RemoveValue(collection, item);
                    }
                }

                // When the first time a property or collection is being loaded, we remove all items other than the ones that we receive.
                if (!isContinuation)
                {
                    IEnumerable <object> itemsToRemove;

                    if (this.EntityTrackingAdapter.MergeOption == MergeOption.OverwriteChanges)
                    {
                        itemsToRemove = linkedItemsInCollection.Select(i => i.Target);
                    }
                    else
                    {
                        Debug.Assert(
                            this.EntityTrackingAdapter.MergeOption == MergeOption.PreserveChanges,
                            "this.EntityTrackingAdapter.MergeOption == MergeOption.PreserveChanges");

                        itemsToRemove = linkedItemsInCollection
                                        .Where(i => !i.IsModified)
                                        .Select(i => i.Target);
                    }

                    itemsToRemove = itemsToRemove.Except(itemsEnumerable);

                    foreach (var item in itemsToRemove)
                    {
                        if (collection != null)
                        {
                            property.RemoveValue(collection, item);
                        }

                        this.EntityTrackingAdapter.MaterializationLog.RemovedLink(entry, property.PropertyName, item);
                    }
                }
            }
        }
 internal static List <TTarget> ListAsElementType <T, TTarget>(object materializer, IEnumerable <T> source) where T : TTarget
 {
     return(ODataEntityMaterializer.ListAsElementType <T, TTarget>((ODataEntityMaterializer)materializer, source));
 }
Exemplo n.º 12
0
 /// <summary>Creates a list to a target element type.</summary>
 /// <param name="materializer">Materializer used to flow link tracking.</param>
 /// <typeparam name="T">Element type to enumerate over.</typeparam>
 /// <typeparam name="TTarget">Element type for list.</typeparam>
 /// <param name="source">Element source.</param>
 /// <returns>
 /// An IEnumerable&lt;T&gt; that iterates over the specified <paramref name="source"/>.
 /// </returns>
 /// <remarks>
 /// This method should be unnecessary with .NET 4.0 covariance support.
 /// </remarks>
 internal static List <TTarget> ListAsElementType <T, TTarget>(object materializer, IEnumerable <T> source) where T : TTarget
 {
     Debug.Assert(typeof(ODataEntityMaterializer).IsAssignableFrom(materializer.GetType()), "typeof(ODataEntityMaterializer).IsAssignableFrom(materializer.GetType())");
     return(ODataEntityMaterializer.ListAsElementType <T, TTarget>((ODataEntityMaterializer)materializer, source));
 }
Exemplo n.º 13
0
 /// <summary>Enumerates casting each element to a type.</summary>
 /// <typeparam name="T">Element type to enumerate over.</typeparam>
 /// <param name="source">Element source.</param>
 /// <returns>
 /// An IEnumerable&lt;T&gt; that iterates over the specified <paramref name="source"/>.
 /// </returns>
 /// <remarks>
 /// This method should be unnecessary with .NET 4.0 covariance support.
 /// </remarks>
 internal static IEnumerable <T> EnumerateAsElementType <T>(IEnumerable source)
 {
     return(ODataEntityMaterializer.EnumerateAsElementType <T>(source));
 }
Exemplo n.º 14
0
 /// <summary>Materializes an entry without including in-lined expanded links.</summary>
 /// <param name="materializer">Materializer under which materialization should take place.</param>
 /// <param name="entry">Entry with object to materialize.</param>
 /// <param name="expectedEntryType">Expected type for the entry.</param>
 /// <returns>The materialized instance.</returns>
 internal static object ShallowMaterializePlan(object materializer, object entry, Type expectedEntryType)
 {
     Debug.Assert(typeof(ODataEntityMaterializer).IsAssignableFrom(materializer.GetType()), "typeof(ODataEntityMaterializer).IsAssignableFrom(materializer.GetType())");
     Debug.Assert(entry.GetType() == typeof(ODataEntry), "entry.GetType() == typeof(ODataEntry)");
     return(ODataEntityMaterializer.ShallowMaterializePlan((ODataEntityMaterializer)materializer, MaterializerEntry.GetEntry((ODataEntry)entry), expectedEntryType));
 }
 internal static bool ProjectionCheckValueForPathIsNull(object entry, Type expectedType, object path)
 {
     return(ODataEntityMaterializer.ProjectionCheckValueForPathIsNull(MaterializerEntry.GetEntry((ODataEntry)entry), expectedType, (ProjectionPath)path));
 }
Exemplo n.º 16
0
 /// <summary>Provides support for getting payload entries or null during projections.</summary>
 /// <param name="entry">Entry to get sub-entry from.</param>
 /// <param name="name">Name of sub-entry.</param>
 /// <returns>The sub-entry or null.</returns>
 internal static object ProjectionGetEntryOrNull(object entry, string name)
 {
     Debug.Assert(entry.GetType() == typeof(ODataEntry), "entry.GetType() == typeof(ODataEntry)");
     return(ODataEntityMaterializer.ProjectionGetEntryOrNull(MaterializerEntry.GetEntry((ODataEntry)entry), name));
 }
Exemplo n.º 17
0
 internal static object ShallowMaterializePlan(ODataEntityMaterializer materializer, MaterializerEntry entry, Type expectedEntryType)
 {
     materializer.Materialize(entry, expectedEntryType, false);
     return(entry.ResolvedObject);
 }
Exemplo n.º 18
0
        internal static object ProjectionValueForPath(ODataEntityMaterializer materializer, MaterializerEntry entry, Type expectedType, ProjectionPath path)
        {
            if ((path.Count == 0) || ((path.Count == 1) && (path[0].Member == null)))
            {
                if (!entry.EntityHasBeenResolved)
                {
                    materializer.Materialize(entry, expectedType, false);
                }
                return(entry.ResolvedObject);
            }
            object streamLink                = null;
            ODataNavigationLink link         = null;
            ODataProperty       atomProperty = null;
            ICollection <ODataNavigationLink> navigationLinks = entry.NavigationLinks;
            IEnumerable <ODataProperty>       properties      = entry.Entry.Properties;
            ClientEdmModel model = ClientEdmModel.GetModel(materializer.ResponseInfo.MaxProtocolVersion);

            for (int i = 0; i < path.Count; i++)
            {
                Func <StreamDescriptor, bool>    predicate = null;
                Func <ODataNavigationLink, bool> func2     = null;
                Func <ODataProperty, bool>       func3     = null;
                Func <ODataProperty, bool>       func4     = null;
                Func <ODataNavigationLink, bool> func5     = null;
                string propertyName;
                ProjectionPathSegment segment = path[i];
                if (segment.Member != null)
                {
                    bool flag = i == (path.Count - 1);
                    propertyName = segment.Member;
                    expectedType = segment.SourceTypeAs ?? expectedType;
                    ClientPropertyAnnotation property = model.GetClientTypeAnnotation(model.GetOrCreateEdmType(expectedType)).GetProperty(propertyName, false);
                    if (property.IsStreamLinkProperty)
                    {
                        if (predicate == null)
                        {
                            predicate = sd => sd.Name == propertyName;
                        }
                        StreamDescriptor descriptor = entry.EntityDescriptor.StreamDescriptors.Where <StreamDescriptor>(predicate).SingleOrDefault <StreamDescriptor>();
                        if (descriptor == null)
                        {
                            if (segment.SourceTypeAs == null)
                            {
                                throw new InvalidOperationException(System.Data.Services.Client.Strings.AtomMaterializer_PropertyMissing(propertyName, entry.Entry.Id));
                            }
                            return(WebUtil.GetDefaultValue <DataServiceStreamLink>());
                        }
                        streamLink = descriptor.StreamLink;
                    }
                    else
                    {
                        if (segment.SourceTypeAs != null)
                        {
                            if (func2 == null)
                            {
                                func2 = p => p.Name == propertyName;
                            }
                            if (!navigationLinks.Any <ODataNavigationLink>(func2))
                            {
                                if (func3 == null)
                                {
                                    func3 = p => p.Name == propertyName;
                                }
                                if (!properties.Any <ODataProperty>(func3) && flag)
                                {
                                    return(WebUtil.GetDefaultValue(property.PropertyType));
                                }
                            }
                        }
                        if (func4 == null)
                        {
                            func4 = p => p.Name == propertyName;
                        }
                        atomProperty = properties.Where <ODataProperty>(func4).FirstOrDefault <ODataProperty>();
                        if (func5 == null)
                        {
                            func5 = p => p.Name == propertyName;
                        }
                        link = ((atomProperty == null) && (navigationLinks != null)) ? navigationLinks.Where <ODataNavigationLink>(func5).FirstOrDefault <ODataNavigationLink>() : null;
                        if ((link == null) && (atomProperty == null))
                        {
                            throw new InvalidOperationException(System.Data.Services.Client.Strings.AtomMaterializer_PropertyMissing(propertyName, entry.Entry.Id));
                        }
                        if (link != null)
                        {
                            ValidatePropertyMatch(property, link);
                            MaterializerNavigationLink link2 = MaterializerNavigationLink.GetLink(link);
                            if (link2.Feed != null)
                            {
                                MaterializerFeed feed = MaterializerFeed.GetFeed(link2.Feed);
                                Type             implementationType = ClientTypeUtil.GetImplementationType(segment.ProjectionType, typeof(ICollection <>));
                                if (implementationType == null)
                                {
                                    implementationType = ClientTypeUtil.GetImplementationType(segment.ProjectionType, typeof(IEnumerable <>));
                                }
                                Type nestedExpectedType = implementationType.GetGenericArguments()[0];
                                Type projectionType     = segment.ProjectionType;
                                if (projectionType.IsInterfaceEx() || ODataMaterializer.IsDataServiceCollection(projectionType))
                                {
                                    projectionType = typeof(Collection <>).MakeGenericType(new Type[] { nestedExpectedType });
                                }
                                IEnumerable list = (IEnumerable)Util.ActivatorCreateInstance(projectionType, new object[0]);
                                MaterializeToList(materializer, list, nestedExpectedType, feed.Entries);
                                if (ODataMaterializer.IsDataServiceCollection(segment.ProjectionType))
                                {
                                    list = (IEnumerable)Util.ActivatorCreateInstance(WebUtil.GetDataServiceCollectionOfT(new Type[] { nestedExpectedType }), new object[] { list, TrackingMode.None });
                                }
                                ProjectionPlan plan = CreatePlanForShallowMaterialization(nestedExpectedType);
                                materializer.FoundNextLinkForCollection(list, feed.Feed.NextPageLink, plan);
                                streamLink = list;
                            }
                            else if (link2.Entry != null)
                            {
                                MaterializerEntry entry2 = link2.Entry;
                                if (flag)
                                {
                                    if ((entry2.Entry != null) && !entry2.EntityHasBeenResolved)
                                    {
                                        materializer.Materialize(entry2, property.PropertyType, false);
                                    }
                                }
                                else
                                {
                                    CheckEntryToAccessNotNull(entry2, propertyName);
                                }
                                properties      = entry2.Properties;
                                navigationLinks = entry2.NavigationLinks;
                                streamLink      = entry2.ResolvedObject;
                                entry           = entry2;
                            }
                        }
                        else
                        {
                            if (atomProperty.Value is ODataStreamReferenceValue)
                            {
                                streamLink      = null;
                                navigationLinks = ODataMaterializer.EmptyLinks;
                                properties      = ODataMaterializer.EmptyProperties;
                                continue;
                            }
                            ValidatePropertyMatch(property, atomProperty);
                            if (ClientTypeUtil.TypeOrElementTypeIsEntity(property.PropertyType))
                            {
                                throw System.Data.Services.Client.Error.InvalidOperation(System.Data.Services.Client.Strings.AtomMaterializer_InvalidEntityType(property.EntityCollectionItemType ?? property.PropertyType));
                            }
                            if (property.IsPrimitiveOrComplexCollection)
                            {
                                object instance = streamLink ?? (entry.ResolvedObject ?? Util.ActivatorCreateInstance(expectedType, new object[0]));
                                ODataMaterializer.ApplyDataValue(model.GetClientTypeAnnotation(model.GetOrCreateEdmType(instance.GetType())), atomProperty, materializer.ResponseInfo.IgnoreMissingProperties, materializer.ResponseInfo, instance);
                                navigationLinks = ODataMaterializer.EmptyLinks;
                                properties      = ODataMaterializer.EmptyProperties;
                            }
                            else if (atomProperty.Value is ODataComplexValue)
                            {
                                ODataComplexValue complexValue = atomProperty.Value as ODataComplexValue;
                                ODataMaterializer.MaterializeComplexTypeProperty(property.PropertyType, complexValue, materializer.ResponseInfo.IgnoreMissingProperties, materializer.ResponseInfo);
                                properties      = complexValue.Properties;
                                navigationLinks = ODataMaterializer.EmptyLinks;
                            }
                            else
                            {
                                if ((atomProperty.Value == null) && !ClientTypeUtil.CanAssignNull(property.NullablePropertyType))
                                {
                                    throw new InvalidOperationException(System.Data.Services.Client.Strings.AtomMaterializer_CannotAssignNull(atomProperty.Name, property.NullablePropertyType));
                                }
                                ODataMaterializer.MaterializePrimitiveDataValue(property.NullablePropertyType, atomProperty);
                                navigationLinks = ODataMaterializer.EmptyLinks;
                                properties      = ODataMaterializer.EmptyProperties;
                            }
                            streamLink = atomProperty.GetMaterializedValue();
                        }
                    }
                    expectedType = property.PropertyType;
                }
            }
            return(streamLink);
        }
 internal static object ProjectionGetEntry(object entry, string name)
 {
     return(ODataEntityMaterializer.ProjectionGetEntry(MaterializerEntry.GetEntry((ODataEntry)entry), name));
 }
 internal static object ProjectionInitializeEntity(object materializer, object entry, Type expectedType, Type resultType, string[] properties, Func <object, object, Type, object>[] propertyValues)
 {
     return(ODataEntityMaterializer.ProjectionInitializeEntity((ODataEntityMaterializer)materializer, MaterializerEntry.GetEntry((ODataEntry)entry), expectedType, resultType, properties, propertyValues));
 }
 internal static IEnumerable ProjectionSelect(object materializer, object entry, Type expectedType, Type resultType, object path, Func <object, object, Type, object> selector)
 {
     return(ODataEntityMaterializer.ProjectionSelect((ODataEntityMaterializer)materializer, MaterializerEntry.GetEntry((ODataEntry)entry), expectedType, resultType, (ProjectionPath)path, selector));
 }
 internal static object ProjectionValueForPath(object materializer, object entry, Type expectedType, object path)
 {
     return(ODataEntityMaterializer.ProjectionValueForPath((ODataEntityMaterializer)materializer, MaterializerEntry.GetEntry((ODataEntry)entry), expectedType, (ProjectionPath)path));
 }
 internal static object ShallowMaterializePlan(object materializer, object entry, Type expectedEntryType)
 {
     return(ODataEntityMaterializer.ShallowMaterializePlan((ODataEntityMaterializer)materializer, MaterializerEntry.GetEntry((ODataEntry)entry), expectedEntryType));
 }