示例#1
0
        private static object ConvertResourceSet(ODataMessageReader oDataMessageReader,
                                                 IEdmTypeReference edmTypeReference, ODataDeserializerContext readContext)
        {
            IEdmCollectionTypeReference collectionType = edmTypeReference.AsCollection();

            EdmEntitySet tempEntitySet = null;

            if (collectionType.ElementType().IsEntity())
            {
                tempEntitySet = new EdmEntitySet(readContext.Model.EntityContainer, "temp",
                                                 collectionType.ElementType().AsEntity().EntityDefinition());
            }

            // TODO: Sam xu, can we use the parameter-less overload
            ODataReader odataReader = oDataMessageReader.CreateODataUriParameterResourceSetReader(tempEntitySet,
                                                                                                  collectionType.ElementType().AsStructured().StructuredDefinition());
            ODataResourceSetWrapper resourceSet =
                odataReader.ReadResourceOrResourceSet() as ODataResourceSetWrapper;

            ODataDeserializerProvider deserializerProvider = readContext.InternalRequest.DeserializerProvider;

            ODataResourceSetDeserializer resourceSetDeserializer =
                (ODataResourceSetDeserializer)deserializerProvider.GetEdmTypeDeserializer(collectionType);

            object      result     = resourceSetDeserializer.ReadInline(resourceSet, collectionType, readContext);
            IEnumerable enumerable = result as IEnumerable;

            if (enumerable != null)
            {
                IEnumerable newEnumerable = enumerable;
                if (collectionType.ElementType().IsEntity())
                {
                    newEnumerable = CovertResourceSetIds(enumerable, resourceSet, collectionType, readContext);
                }

                if (readContext.IsUntyped)
                {
                    return(newEnumerable.ConvertToEdmObject(collectionType));
                }
                else
                {
                    IEdmTypeReference elementTypeReference = collectionType.ElementType();

                    Type elementClrType = EdmLibHelpers.GetClrType(elementTypeReference,
                                                                   readContext.Model);
                    IEnumerable castedResult =
                        CastMethodInfo.MakeGenericMethod(elementClrType)
                        .Invoke(null, new object[] { newEnumerable }) as IEnumerable;
                    return(castedResult);
                }
            }

            return(null);
        }
示例#2
0
        public Type GetClrType(IEdmTypeReference edmType, IEdmModel edmModel)
        {
            Type clrType;

            if (!_edmToClrTypeCache.TryGetValue(edmType, out clrType))
            {
                clrType = EdmLibHelpers.GetClrType(edmType, edmModel);
                _edmToClrTypeCache[edmType] = clrType;
            }

            return(clrType);
        }
示例#3
0
        public Type GetClrType(IEdmTypeReference edmType, IEdmModel edmModel)
        {
            Type clrType;

            EdmTypeCacheItem item = new EdmTypeCacheItem(edmType.Definition, edmType.IsNullable);

            if (!_edmToClrTypeCache.TryGetValue(item, out clrType))
            {
                clrType = EdmLibHelpers.GetClrType(edmType, edmModel);
                _edmToClrTypeCache[item] = clrType;
            }

            return(clrType);
        }