예제 #1
0
        /// <summary>
        ///		Asynchronously read the body content as the specified type.
        /// </summary>
        /// <typeparam name="TBody">
        ///		The CLR data-type that the body content will be deserialised into.
        /// </typeparam>
        /// <param name="content">
        ///		The <see cref="HttpContent"/> to read.
        /// </param>
        /// <param name="formatter">
        ///		The content formatter used to deserialise the body content.
        /// </param>
        /// <returns>
        ///		The deserialised body content.
        /// </returns>
        public static Task <TBody> ReadAsAsync <TBody>(this HttpContent content, IInputFormatter formatter)
        {
            if (content == null)
            {
                throw new ArgumentNullException(nameof(content));
            }

            InputFormatterContext formatterContext = content.CreateInputFormatterContext <TBody>();

            return(content.ReadAsAsync <TBody>(formatter, formatterContext));
        }