Last active
August 14, 2017 15:35
-
-
Save gtarsia/e312f289ba149b33c951c1f95f9de29b 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
using Newtonsoft.Json; | |
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
public static class StreamExtensions | |
{ | |
public static IEnumerable<TResult> ReadJson<TResult>(this Stream stream) | |
{ | |
var serializer = new JsonSerializer(); | |
using (var reader = new StreamReader(stream)) | |
using (var jsonReader = new JsonTextReader(reader)) | |
{ | |
jsonReader.SupportMultipleContent = true; | |
while (jsonReader.Read()) | |
{ | |
if (jsonReader.TokenType == JsonToken.StartObject) | |
{ | |
yield return serializer.Deserialize<TResult>(jsonReader); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment