﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="MinimalJsonSerializer.cs">
//   Copyright (c) 2016. All rights reserved.
//   Licensed under the MIT license. See LICENSE file in the project root for full license information.
// </copyright>
// <auto-generated>
//   Sourced from NuGet package. Will be overwritten with package update except in Spritely.Recipes source.
// </auto-generated>
// --------------------------------------------------------------------------------------------------------------------

namespace Spritely.Recipes
{
    using System;

    using Newtonsoft.Json;

    /// <summary>
    /// This is a wrapper around <see cref="T:Newtonsoft.Json.JsonConvert" /> that uses the 
    /// serialization settings from <see cref="JsonConfiguration.MinimalSerializerSettings" />.
    /// This is for internal use-cases where these settings are specifically required and
    /// where the caller does not want to rely on
    /// <see cref="T:Newtonsoft.Json.JsonConvert.DefaultSettings" />
    /// </summary>
#if !SpritelyRecipesProject
    [System.Diagnostics.DebuggerStepThrough]
    [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
    [System.CodeDom.Compiler.GeneratedCode("Spritely.Recipes", "See package version number")]
#pragma warning disable 0436
#endif
    internal static partial class MinimalJsonSerializer
    {
        /// <summary>
        /// Deserializes the JSON to the specified .NET type.
        /// </summary>
        /// <typeparam name="T">The type of the object to deserialize to.</typeparam>
        /// <param name="value">The JSON to deserialize.</param>
        /// <returns>The deserialized object from the JSON string.</returns>
        public static T DeserializeObject<T>(string value) where T : class
        {
            var result = JsonConvert.DeserializeObject<T>(value, JsonConfiguration.MinimalSerializerSettings);
            return result;
        }

        /// <summary>
        /// Deserializes the JSON to a .NET object.
        /// </summary>
        /// <param name="value">JSON to deserialize.</param>
        /// <returns>The deserialized object from the JSON string.</returns>
        public static object DeserializeObject(string value)
        {
            var result = JsonConvert.DeserializeObject(value, JsonConfiguration.MinimalSerializerSettings);
            return result;
        }

        /// <summary>
        /// Deserializes the JSON to the specified .NET type.
        /// </summary>
        /// <param name="value">The JSON to deserialize.</param>
        /// <param name="type">The Type of object being deserialized.</param>
        /// <returns>The deserialized object from the JSON string.</returns>
        public static object DeserializeObject(string value, Type type)
        {
            var result = JsonConvert.DeserializeObject(value, type, JsonConfiguration.MinimalSerializerSettings);
            return result;
        }

        /// <summary>
        /// Serializes the specified object to a JSON string.
        /// </summary>
        /// <param name="value">The object to serialize.</param>
        /// <returns>A JSON string representation of the object.</returns>
        public static string SerializeObject(object value)
        {
            var result = JsonConvert.SerializeObject(value, JsonConfiguration.MinimalSerializerSettings);
            return result;
        }
    }
#if !SpritelyRecipesProject
#pragma warning restore 0436
#endif
}
