Beispiel #1
0
        /// <summary>
        /// Converts a list of CosmosElements into a list of objects.
        /// </summary>
        /// <param name="cosmosElements">The cosmos elements</param>
        /// <param name="jsonSerializer">The JSON </param>
        /// <param name="cosmosSerializationOptions">The custom serialization options. This allows custom serialization types like BSON, JSON, or other formats</param>
        /// <returns>Returns a memory stream of cosmos elements. By default the memory stream will contain JSON.</returns>
        internal static IEnumerable <T> Deserialize <T>(
            IEnumerable <CosmosElement> cosmosElements,
            CosmosJsonSerializer jsonSerializer,
            CosmosSerializationOptions cosmosSerializationOptions = null)
        {
            if (!cosmosElements.Any())
            {
                return(Enumerable.Empty <T>());
            }

            Stream          stream       = CosmosElementSerializer.ToStream(cosmosElements, cosmosSerializationOptions);
            IEnumerable <T> typedResults = jsonSerializer.FromStream <List <T> >(stream);

            return(typedResults);
        }
Beispiel #2
0
        /// <summary>
        /// Converts a list of CosmosElements into a list of objects.
        /// </summary>
        /// <param name="containerRid">Container Rid</param>
        /// <param name="cosmosElements">The cosmos elements</param>
        /// <param name="resourceType">The resource type</param>
        /// <param name="jsonSerializer">The JSON </param>
        /// <param name="cosmosSerializationOptions">The custom serialization options. This allows custom serialization types like BSON, JSON, or other formats</param>
        /// <returns>Returns a list of deserialized objects</returns>
        internal static IEnumerable <T> Deserialize <T>(
            string containerRid,
            IEnumerable <CosmosElement> cosmosElements,
            ResourceType resourceType,
            CosmosJsonSerializer jsonSerializer,
            CosmosSerializationOptions cosmosSerializationOptions = null)
        {
            if (!cosmosElements.Any())
            {
                return(Enumerable.Empty <T>());
            }

            Stream stream = CosmosElementSerializer.ToStream(
                containerRid,
                cosmosElements,
                resourceType,
                cosmosSerializationOptions);

            IEnumerable <T> typedResults = jsonSerializer.FromStream <CosmosFeedResponseUtil <T> >(stream).Data;

            return(typedResults);
        }