using System;
using System.IO;
using System.Reflection;
namespace Microsoft.AspNetCore.NodeServices
{
///
/// Contains methods for reading embedded resources.
///
public static class EmbeddedResourceReader
{
///
/// Reads the specified embedded resource from a given assembly.
///
/// Any in the assembly whose resource is to be read.
/// The path of the resource to be read.
/// The contents of the resource.
public static string Read(Type assemblyContainingType, string path)
{
var asm = assemblyContainingType.GetTypeInfo().Assembly;
var embeddedResourceName = asm.GetName().Name + path.Replace("/", ".");
using (var stream = asm.GetManifestResourceStream(embeddedResourceName))
using (var sr = new StreamReader(stream))
{
return sr.ReadToEnd();
}
}
}
}