GetClrType() public static method

public static GetClrType ( IEdmType edmType, IEdmModel edmModel, IAssembliesResolver assembliesResolver ) : Type
edmType IEdmType
edmModel IEdmModel
assembliesResolver IAssembliesResolver
return Type
Exemplo n.º 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.Request.GetDeserializerProvider();

            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);
        }
Exemplo n.º 2
0
            internal static object ConvertFeed(ODataMessageReader oDataMessageReader, IEdmTypeReference edmTypeReference, ODataDeserializerContext readContext)
            {
                IEdmCollectionTypeReference collectionType = edmTypeReference.AsCollection();

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

                ODataReader odataReader = oDataMessageReader.CreateODataFeedReader(tempEntitySet,
                                                                                   collectionType.ElementType().AsEntity().EntityDefinition());
                ODataFeedWithEntries feed =
                    ODataEntityDeserializer.ReadEntryOrFeed(odataReader) as ODataFeedWithEntries;

                ODataFeedDeserializer feedDeserializer =
                    (ODataFeedDeserializer)DeserializerProvider.GetEdmTypeDeserializer(collectionType);

                object      result     = feedDeserializer.ReadInline(feed, collectionType, readContext);
                IEnumerable enumerable = result as IEnumerable;

                if (enumerable != null)
                {
                    IEnumerable newEnumerable = CovertFeedIds(enumerable, feed, collectionType, readContext);
                    if (readContext.IsUntyped)
                    {
                        EdmEntityObjectCollection entityCollection =
                            new EdmEntityObjectCollection(collectionType);
                        foreach (EdmEntityObject entity in newEnumerable)
                        {
                            entityCollection.Add(entity);
                        }

                        return(entityCollection);
                    }
                    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);
            }
Exemplo n.º 3
0
 public void GetClrType_ReturnsRightClrType(IEdmTypeReference edmTypeReference, Type expectedType)
 {
     Assert.Same(expectedType, EdmLibHelpers.GetClrType(edmTypeReference, GetEdmModel()));
 }