#region usings
using System;
using System.IO;
using System.Reflection;
#endregion
namespace SM.Utility
{
///
/// Contains utility functions for handling with assemblies.
///
public class AssemblyUtility
{
///
/// Read a file that is saved in a assembly
///
/// The assembly that contains the file
/// The path to the file inside the assembly
///
public static string ReadAssemblyFile(Assembly ass, string path)
{
return new StreamReader(GetAssemblyStream(ass, path)).ReadToEnd();
}
///
/// Read a file that is saved in the calling assembly
///
/// The path to the file inside the assembly
///
public static string ReadAssemblyFile(string path)
{
return ReadAssemblyFile(Assembly.GetCallingAssembly(), path);
}
///
/// Returns a stream of a requested resource.
///
/// The assembly the resource is in.
/// The path to the resource.
/// The stream
public static Stream GetAssemblyStream(Assembly ass, string path)
{
return ass.GetManifestResourceStream(path) ??
throw new InvalidOperationException("Assembly couldn't find resource at path '" + path + "'.");
}
///
/// Returns a stream of a requested resource in the calling assembly.
///
/// The path to the resource
/// The stream
public static Stream GetAssemblyStream(string path)
{
return GetAssemblyStream(Assembly.GetCallingAssembly(), path);
}
}
}