示例#1
0
        /// <summary>
        /// <para>从指定的<paramref name="stream"/>反序列化给定类型的值</para>
        /// <para>Deserializes the value of the given type from the specified <paramref name="stream"/></para>
        /// </summary>
        /// <param name="context">反序列化所需要的上下文. The context required for the deserialization </param>
        /// <param name="stream">要进行反序列化的流. The stream to deserialize from</param>
        /// <returns>反序列化的值. The deserialized value</returns>
        public static T Deserialize <T>(ref BssomDeserializeContext context, Stream stream)
        {
            if (TryDeserializeFromMemoryStream <T>(ref context, stream, out T result))
            {
                return(result);
            }

            StreamDeserializeAux aux = new StreamDeserializeAux(stream);

            result = Deserialize <T>(ref context, aux.GetBssomBuffer());
            aux.Dispose();
            return(result);
        }
示例#2
0
        /// <summary>
        /// <para>异步的从指定的<paramref name="stream"/>反序列化给定类型的值</para>
        /// <para>Asynchronously deserializes the value of the given type from the specified <paramref name="stream"/></para>
        /// </summary>
        /// <param name="stream">反序列化所需要的的流. The stream to deserialize from</param>
        /// <param name="option">使用的配置,如果为<c>null</c>,则使用默认配置. The options. Use <c>null</c> to use default options</param>
        /// <param name="cancellationToken">取消该操作的令牌. The token to cancel the operation</param>
        /// <returns>反序列化的值. The deserialized value</returns>
        public static async Task <T> DeserializeAsync <T>(Stream stream, BssomSerializerOptions option = null,
                                                          CancellationToken cancellationToken          = default)
        {
            BssomDeserializeContext context = new BssomDeserializeContext(option, cancellationToken);

            if (TryDeserializeFromMemoryStream <T>(ref context, stream, out T result))
            {
                return(result);
            }

            StreamDeserializeAux aux      = new StreamDeserializeAux(stream);
            IBssomBuffer         bssomBuf = await aux.GetBssomBufferAsync().ConfigureAwait(false);

            result = Deserialize <T>(ref context, bssomBuf);
            aux.Dispose();
            return(result);
        }
示例#3
0
        /// <summary>
        /// <para>从指定的<paramref name="stream"/>反序列化给定类型的值</para>
        /// <para>Deserializes the value of the given type from the specified <paramref name="stream"/></para>
        /// </summary>
        /// <param name="context">反序列化所需要的上下文. The context required for the deserialization </param>
        /// <param name="stream">反序列化所需要的的缓冲区. The stream to deserialize from</param>
        /// <param name="type">要反序列化的类型. The type to deserialize</param>
        /// <returns>反序列化的值. The deserialized value</returns>
        public static object Deserialize(ref BssomDeserializeContext context, Stream stream, Type type)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            if (TryDeserializeFromMemoryStream(ref context, stream, type, out object result))
            {
                return(result);
            }

            StreamDeserializeAux aux = new StreamDeserializeAux(stream);

            result = Deserialize(ref context, aux.GetBssomBuffer(), type);
            aux.Dispose();
            return(result);
        }
示例#4
0
        /// <summary>
        /// <para>异步的从指定的<paramref name="stream"/>反序列化给定类型的值</para>
        /// <para>Asynchronously deserializes the value of the given type from the specified <paramref name="stream"/></para>
        /// </summary>
        /// <param name="stream">反序列化所需要的的流. The stream to deserialize from</param>
        /// <param name="type">要反序列化的类型. The type to deserialize</param>
        /// <param name="option">使用的配置,如果为<c>null</c>,则使用默认配置. The options. Use <c>null</c> to use default options</param>
        /// <param name="cancellationToken">取消该操作的令牌. The token to cancel the operation</param>
        /// <returns>反序列化的值. The deserialized value</returns>
        public static async Task <object> DeserializeAsync(Stream stream, Type type, BssomSerializerOptions option = null,
                                                           CancellationToken cancellationToken = default)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            BssomDeserializeContext context = new BssomDeserializeContext(option, cancellationToken);

            if (TryDeserializeFromMemoryStream(ref context, stream, out object result))
            {
                return(result);
            }

            StreamDeserializeAux aux      = new StreamDeserializeAux(stream);
            IBssomBuffer         bssomBuf = await aux.GetBssomBufferAsync().ConfigureAwait(false);

            result = Deserialize(ref context, bssomBuf, type);
            aux.Dispose();
            return(result);
        }