forked from ddrilling/AsbCloudServer
25 lines
651 B
C#
25 lines
651 B
C#
|
using System.Reflection;
|
||
|
|
||
|
namespace AsbCloudWebApi.IntegrationTests;
|
||
|
|
||
|
internal static class AssemblyExtensions
|
||
|
{
|
||
|
internal static Stream GetFileCopyStream(this Assembly assembly, string templateName)
|
||
|
{
|
||
|
var resourceName = assembly
|
||
|
.GetManifestResourceNames()
|
||
|
.FirstOrDefault(n => n.EndsWith(templateName));
|
||
|
|
||
|
if (string.IsNullOrWhiteSpace(resourceName))
|
||
|
throw new ArgumentNullException(nameof(resourceName));
|
||
|
|
||
|
using var stream = Assembly.GetExecutingAssembly()
|
||
|
.GetManifestResourceStream(resourceName);
|
||
|
|
||
|
var memoryStream = new MemoryStream();
|
||
|
stream?.CopyTo(memoryStream);
|
||
|
memoryStream.Position = 0;
|
||
|
|
||
|
return memoryStream;
|
||
|
}
|
||
|
}
|