Last active
November 15, 2019 07:03
-
-
Save stijnmoreels/0bf6c64660c1da10dcea94ce3684bfc6 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
private static Outcome<JObject, string[]> Load(Stream content) | |
{ | |
if (content is null) | |
{ | |
throw new ArgumentNullException(nameof(content)); | |
} | |
var settings = new JsonLoadSettings | |
{ | |
CommentHandling = CommentHandling.Ignore, | |
DuplicatePropertyNameHandling = DuplicatePropertyNameHandling.Error, | |
LineInfoHandling = LineInfoHandling.Ignore | |
}; | |
using var strReader = new StreamReader(content); | |
using var txtReader = new JsonTextReader(strReader); | |
try | |
{ | |
return JObject.Load(txtReader, settings); | |
} | |
catch (JsonReaderException ex) | |
{ | |
Logger.Error(ex, "Invalid JSON content stream caused an exception"); | |
return new [] { "Content cannot be parsed to valid JSON" }; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment