23 lines
769 B
C#
23 lines
769 B
C#
using System.Reflection;
|
|
using System.Text;
|
|
|
|
namespace MangaReader.Tests.Utilities;
|
|
|
|
public static class ResourceHelper
|
|
{
|
|
/// <summary>
|
|
/// Reads an embedded JSON resource from the calling assembly.
|
|
/// </summary>
|
|
/// <param name="resourceName">The full resource name, e.g. "MyNamespace.Folder.sample.json".</param>
|
|
public static async Task<string> ReadJsonResourceAsync(string resourceName)
|
|
{
|
|
Assembly assmbly = Assembly.GetExecutingAssembly();
|
|
|
|
using Stream? stream = assmbly.GetManifestResourceStream(resourceName)
|
|
?? throw new FileNotFoundException($"Resource '{resourceName}' not found.");
|
|
|
|
using StreamReader reader = new(stream, Encoding.UTF8);
|
|
|
|
return await reader.ReadToEndAsync();
|
|
}
|
|
} |