private static void AddToBackingStore(EntryLimitedDictionary backingStore, string prefix, object value)
    {
        IDictionary <string, object> strs = value as IDictionary <string, object>;

        if (strs != null)
        {
            foreach (KeyValuePair <string, object> keyValuePair in strs)
            {
                CustomJsonValueProviderFactory.AddToBackingStore(backingStore, CustomJsonValueProviderFactory.MakePropertyKey(prefix, keyValuePair.Key), keyValuePair.Value);
            }

            return;
        }

        IList lists = value as IList;

        if (lists == null)
        {
            backingStore.Add(prefix, value);
            return;
        }

        for (int i = 0; i < lists.Count; i++)
        {
            CustomJsonValueProviderFactory.AddToBackingStore(backingStore, CustomJsonValueProviderFactory.MakeArrayKey(prefix, i), lists[i]);
        }
    }
    /// <summary>Returns a JSON value-provider object for the specified controller context.</summary>
    /// <returns>A JSON value-provider object for the specified controller context.</returns>
    /// <param name="controllerContext">The controller context.</param>
    public override IValueProvider GetValueProvider(ControllerContext controllerContext)
    {
        if (controllerContext == null)
        {
            throw new ArgumentNullException("controllerContext");
        }

        object deserializedObject = CustomJsonValueProviderFactory.GetDeserializedObject(controllerContext);

        if (deserializedObject == null)
        {
            return(null);
        }

        Dictionary <string, object> strs = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase);

        CustomJsonValueProviderFactory.AddToBackingStore(new CustomJsonValueProviderFactory.EntryLimitedDictionary(strs), string.Empty, deserializedObject);

        return(new DictionaryValueProvider <object>(strs, CultureInfo.CurrentCulture));
    }
    private static object GetDeserializedObject(ControllerContext controllerContext)
    {
        if (!controllerContext.HttpContext.Request.ContentType.StartsWith("application/json", StringComparison.OrdinalIgnoreCase))
        {
            return(null);
        }

        string fullStreamString = (new StreamReader(controllerContext.HttpContext.Request.InputStream)).ReadToEnd();

        if (string.IsNullOrEmpty(fullStreamString))
        {
            return(null);
        }

        var serializer = new JavaScriptSerializer()
        {
            MaxJsonLength = CustomJsonValueProviderFactory.GetMaxJsonLength()
        };

        return(serializer.DeserializeObject(fullStreamString));
    }
 static EntryLimitedDictionary()
 {
     _maximumDepth = CustomJsonValueProviderFactory.GetMaximumDepth();
 }