Created
July 26, 2018 14:43
-
-
Save kgiszewski/0bc64ad492aa6d07cf7e7b9b02aed297 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 class EmbeddedResourceHelper | |
{ | |
public string GetResource(string resourceLocation, Type type = null) | |
{ | |
using (var stream = GetResourceStream(resourceLocation, type)) | |
{ | |
if (stream == null) | |
{ | |
return string.Empty; | |
} | |
using (var reader = new StreamReader(stream)) | |
{ | |
return reader.ReadToEnd(); | |
} | |
} | |
} | |
public Stream GetResourceStream(string resourceLocation, Type type = null) | |
{ | |
var assembly = type == null ? Assembly.GetExecutingAssembly() : Assembly.GetAssembly(type); | |
return assembly.GetManifestResourceStream(resourceLocation); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment