DD.WellWorkover.Cloud/AsbCloudInfrastructure/AssemblyExtensions.cs

28 lines
735 B
C#
Raw Normal View History

using System;
using System.IO;
using System.Linq;
using System.Reflection;
2024-08-19 10:01:07 +05:00
namespace AsbCloudInfrastructure;
public static class AssemblyExtensions
{
2024-08-19 10:01:07 +05:00
public static Stream GetTemplateCopyStream(this Assembly assembly, string templateName)
{
var resourceName = assembly
.GetManifestResourceNames()
.FirstOrDefault(n => n.EndsWith(templateName));
2024-08-19 10:01:07 +05:00
if (string.IsNullOrWhiteSpace(resourceName))
throw new ArgumentNullException(nameof(resourceName));
2024-08-19 10:01:07 +05:00
using var stream = Assembly.GetExecutingAssembly()
.GetManifestResourceStream(resourceName);
2024-08-19 10:01:07 +05:00
var memoryStream = new MemoryStream();
stream?.CopyTo(memoryStream);
memoryStream.Position = 0;
return memoryStream;
}
2024-08-19 10:01:07 +05:00
}