示例#1
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);
            }
        }
示例#2
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);
        }
示例#3
0
        protected override void ReadFromMessageReader(ODataMessageReader reader, IEdmTypeReference expectedType)
        {
            ODataProperty collectionProperty = reader.ReadProperty(expectedType);
            Type          type = Nullable.GetUnderlyingType(base.ExpectedType) ?? base.ExpectedType;
            object        obj2 = collectionProperty.Value;

            if (expectedType.IsCollection())
            {
                object obj3;
                Type   collectionItemType = type;
                Type   implementationType = ClientTypeUtil.GetImplementationType(type, typeof(ICollection <>));
                if (implementationType != null)
                {
                    collectionItemType = implementationType.GetGenericArguments()[0];
                    obj3 = ODataMaterializer.CreateCollectionInstance(collectionProperty, type, base.ResponseInfo);
                }
                else
                {
                    implementationType = typeof(ICollection <>).MakeGenericType(new Type[] { collectionItemType });
                    obj3 = ODataMaterializer.CreateCollectionInstance(collectionProperty, implementationType, base.ResponseInfo);
                }
                ODataMaterializer.ApplyCollectionDataValues(collectionProperty, base.ResponseInfo.IgnoreMissingProperties, base.ResponseInfo, obj3, collectionItemType, ODataMaterializer.GetAddToCollectionDelegate(implementationType));
                this.currentValue = obj3;
            }
            else if (expectedType.IsComplex())
            {
                ODataComplexValue complexValue = obj2 as ODataComplexValue;
                ODataMaterializer.MaterializeComplexTypeProperty(type, complexValue, base.ResponseInfo.IgnoreMissingProperties, base.ResponseInfo);
                this.currentValue = complexValue.GetMaterializedValue();
            }
            else
            {
                ODataMaterializer.MaterializePrimitiveDataValue(base.ExpectedType, collectionProperty);
                this.currentValue = collectionProperty.GetMaterializedValue();
            }
        }