Created
August 8, 2018 23:08
-
-
Save MattVonVielen/63747dbd110440726e6fed5e004504ba to your computer and use it in GitHub Desktop.
C# - embed JSON sample data in test assembly
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 static T LoadJsonFromResource<T>(string resourceName) where T: class | |
{ | |
using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName)) | |
{ | |
if (stream == null) return null; | |
using (var sr = new StreamReader(stream)) | |
{ | |
using (var reader = new JsonTextReader(sr)) | |
{ | |
return new JsonSerializer().Deserialize<T>(reader); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment