Skip to content

Instantly share code, notes, and snippets.

@adbre
Created February 16, 2014 14:10
Show Gist options
  • Save adbre/9034768 to your computer and use it in GitHub Desktop.
Save adbre/9034768 to your computer and use it in GitHub Desktop.
using System.IO;
namespace System.Reflection
{
public static class AssemblyManifestResourceStreamExtensions
{
public static Stream OpenManifestResourceStream(this Assembly assembly, string name)
{
if (assembly == null) throw new ArgumentNullException("assembly");
var result = assembly.GetManifestResourceStream(name);
if (result != null) return result;
var message = string.Format("Cannot open manifest resource stream, not found. Name: '{0}'", name);
throw new InvalidOperationException(message);
}
public static Stream OpenManifestResourceStream(this Assembly assembly, Type type, string name)
{
if (assembly == null) throw new ArgumentNullException("assembly");
var result = assembly.GetManifestResourceStream(type, name);
if (result != null) return result;
var message = string.Format("Cannot open manifest resource stream, not found. Type: '{0}', Name: '{1}'", type, name);
throw new InvalidOperationException(message);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment