bloxstrap/Bloxstrap/ResourceHelper.cs
pizzaboxer 58fb73c127
Refactor class structure for singletons/utilities
cleanup necessary namespaces and adjust namespaces for certain classes to better represent what they're for
models, helpers and tools are all different and shouldnt really be under the same namespace
2023-04-26 21:14:35 +01:00

28 lines
792 B
C#

using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
namespace Bloxstrap
{
static class ResourceHelper
{
static readonly Assembly assembly = Assembly.GetExecutingAssembly();
static readonly string[] resourceNames = assembly.GetManifestResourceNames();
public static async Task<byte[]> Get(string name)
{
string path = resourceNames.Single(str => str.EndsWith(name));
using (Stream stream = assembly.GetManifestResourceStream(path)!)
{
using (MemoryStream memoryStream = new())
{
await stream.CopyToAsync(memoryStream);
return memoryStream.ToArray();
}
}
}
}
}