Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kgiszewski/0bc64ad492aa6d07cf7e7b9b02aed297 to your computer and use it in GitHub Desktop.
Save kgiszewski/0bc64ad492aa6d07cf7e7b9b02aed297 to your computer and use it in GitHub Desktop.
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