Created
January 10, 2020 19:28
-
-
Save wocar/1701696c54f3498f55685d091eefb0f1 to your computer and use it in GitHub Desktop.
Read embedded resource from assembly
This file contains hidden or 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 class TestExtensions | |
| { | |
| public static string ReadResource(this Assembly assembly, string name) | |
| { | |
| // Determine path | |
| var resourcePath = assembly.GetManifestResourceNames() | |
| .Single(str => str.EndsWith(name));; | |
| using (var stream = assembly.GetManifestResourceStream(resourcePath)) | |
| using (var reader = new StreamReader(stream ?? throw new InvalidOperationException())) | |
| { | |
| return reader.ReadToEnd(); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment