C# loading embedded resource as string

Date: 2023-01-09
using System.IO;
using System.Reflection;

public static string GetEmbeddedResourceAsString(Assembly assembly, string resourceName)
{
    using var stream = assembly.GetManifestResourceStream(resourceName);
    if (stream == null) return string.Empty;
    using var reader = new StreamReader(stream);
    return reader.ReadToEnd();
}

// where resource name is in format: "NameSpace.ResourceFileNameWith.extension"
71730cookie-checkC# loading embedded resource as string