Created
May 20, 2021 10:55
-
-
Save bjoerntx/4410a7ca82e4ff9fbe9f3d36a467b5d4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public sealed class JsonDotNetValueProviderFactory : ValueProviderFactory { | |
public override IValueProvider GetValueProvider(ControllerContext controllerContext) { | |
if (controllerContext == null) | |
throw new ArgumentNullException("controllerContext"); | |
if (!controllerContext.HttpContext.Request.ContentType.StartsWith("application/json", StringComparison.OrdinalIgnoreCase)) | |
return null; | |
var reader = new StreamReader(controllerContext.HttpContext.Request.InputStream); | |
var bodyText = reader.ReadToEnd(); | |
return String.IsNullOrEmpty(bodyText) ? null : new DictionaryValueProvider<object>( | |
JsonConvert.DeserializeObject<ExpandoObject>(bodyText, new ExpandoObjectConverter()), CultureInfo.CurrentCulture); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment