Пример #1
0
 /// <inheritdoc cref="IDeserialize.Deserialize{T}(string)" />
 public static T Deserialize <T>(this IDeserializeObject deserializer, string?value)
 {
     if (deserializer is null)
     {
         throw new ArgumentNullException(nameof(deserializer));
     }
     return(deserializer is IDeserialize d
                         ? d.Deserialize <T>(value)
                         : (T)deserializer.Deserialize(value, typeof(T)) !);
 }
        /// <summary>
        /// Deserializes a stream to the specified type.
        /// </summary>
        public static async ValueTask <object?> DeserializeAsync(IDeserializeObject deserializer, Stream source, Type type)
        {
            if (deserializer is null)
            {
                throw new ArgumentNullException(nameof(deserializer));
            }
            if (source is null)
            {
                throw new ArgumentNullException(nameof(source));
            }
            if (type is null)
            {
                throw new ArgumentNullException(nameof(type));
            }
            string text;

            using (var reader = new StreamReader(source))
                text = await reader.ReadToEndAsync().ConfigureAwait(false);
            return(deserializer.Deserialize(text, type));
        }