private static IEdmTypeReference GetElementType(Type type, ODataDeserializerContext readContext) { IEdmTypeReference edmType = readContext.GetEdmType(type); Contract.Assert(edmType != null); if (!edmType.IsCollection()) { throw Error.Argument("type", SRResources.ArgumentMustBeOfType, EdmTypeKind.Collection); } return(edmType); }
/// <inheritdoc /> public override async Task <object> ReadAsync(ODataMessageReader messageReader, Type type, ODataDeserializerContext readContext) { if (messageReader == null) { throw Error.ArgumentNull("messageReader"); } IEdmTypeReference edmType = readContext.GetEdmType(type); Contract.Assert(edmType != null); ODataProperty property = await messageReader.ReadPropertyAsync(edmType); return(ReadInline(property, edmType, readContext)); }
/// <inheritdoc /> public override object Read(ODataMessageReader messageReader, Type type, ODataDeserializerContext readContext) { if (messageReader == null) { throw Error.ArgumentNull("messageReader"); } if (readContext == null) { throw Error.ArgumentNull("readContext"); } IEdmTypeReference edmType = readContext.GetEdmType(type); Contract.Assert(edmType != null); if (!edmType.IsStructured()) { throw Error.Argument("type", SRResources.ArgumentMustBeOfType, "Structured"); } IEdmStructuredTypeReference structuredType = edmType.AsStructured(); IEdmNavigationSource navigationSource = null; if (structuredType.IsEntity()) { if (readContext.Path == null) { throw Error.Argument("readContext", SRResources.ODataPathMissing); } navigationSource = readContext.Path.NavigationSource; if (navigationSource == null) { throw new SerializationException(SRResources.NavigationSourceMissingDuringDeserialization); } } ODataReader odataReader = messageReader.CreateODataResourceReader(navigationSource, structuredType.StructuredDefinition()); ODataResourceWrapper topLevelResource = odataReader.ReadResourceOrResourceSet() as ODataResourceWrapper; Contract.Assert(topLevelResource != null); return(ReadInline(topLevelResource, structuredType, readContext)); }
private static IEdmStructuredTypeReference GetStructuredType(Type type, ODataDeserializerContext readContext) { if (readContext == null) { throw Error.ArgumentNull("readContext"); } IEdmTypeReference edmType = readContext.GetEdmType(type); Contract.Assert(edmType != null); if (!edmType.IsStructured()) { throw Error.Argument("type", SRResources.ArgumentMustBeOfType, "Structured"); } return(edmType.AsStructured()); }
/// <inheritdoc /> public override object Read(ODataMessageReader messageReader, Type type, ODataDeserializerContext readContext) { if (messageReader == null) { throw Error.ArgumentNull("messageReader"); } IEdmTypeReference edmType = readContext.GetEdmType(type); Contract.Assert(edmType != null); // TODO: is it ok to read the top level collection of entity? if (!(edmType.IsCollection() && edmType.AsCollection().ElementType().IsStructured())) { throw Error.Argument("edmType", SRResources.ArgumentMustBeOfType, EdmTypeKind.Complex + " or " + EdmTypeKind.Entity); } ODataReader resourceSetReader = messageReader.CreateODataResourceSetReader(); object resourceSet = resourceSetReader.ReadResourceOrResourceSet(); return(ReadInline(resourceSet, edmType, readContext)); }
/// <inheritdoc /> public override object Read(ODataMessageReader messageReader, Type type, ODataDeserializerContext readContext) { if (messageReader == null) { throw Error.ArgumentNull("messageReader"); } IEdmTypeReference edmType = readContext.GetEdmType(type); Contract.Assert(edmType != null); if (!edmType.IsCollection()) { throw Error.Argument("type", SRResources.ArgumentMustBeOfType, EdmTypeKind.Collection); } IEdmCollectionTypeReference collectionType = edmType.AsCollection(); IEdmTypeReference elementType = collectionType.ElementType(); ODataCollectionReader reader = messageReader.CreateODataCollectionReader(elementType); return(ReadInline(ReadCollection(reader), edmType, readContext)); }
/// <inheritdoc /> public override object Read(ODataMessageReader messageReader, Type type, ODataDeserializerContext readContext) { if (messageReader == null) { throw Error.ArgumentNull("messageReader"); } if (type == null) { throw Error.ArgumentNull("type"); } if (readContext == null) { throw Error.ArgumentNull("readContext"); } IEdmTypeReference edmType = readContext.GetEdmType(type); Contract.Assert(edmType != null); ODataProperty property = messageReader.ReadProperty(edmType); return(ReadInline(property, edmType, readContext)); }