2024-07-04 11:02:45 +05:00
|
|
|
using System;
|
2023-10-20 11:24:04 +05:00
|
|
|
using System.IO;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Reflection;
|
|
|
|
|
2024-08-19 10:01:07 +05:00
|
|
|
namespace AsbCloudInfrastructure;
|
|
|
|
|
|
|
|
public static class AssemblyExtensions
|
2023-10-20 11:24:04 +05:00
|
|
|
{
|
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-07-04 11:02:45 +05:00
|
|
|
|
2024-08-19 10:01:07 +05:00
|
|
|
if (string.IsNullOrWhiteSpace(resourceName))
|
|
|
|
throw new ArgumentNullException(nameof(resourceName));
|
2024-07-04 11:02:45 +05:00
|
|
|
|
2024-08-19 10:01:07 +05:00
|
|
|
using var stream = Assembly.GetExecutingAssembly()
|
|
|
|
.GetManifestResourceStream(resourceName);
|
2024-07-04 11:02:45 +05:00
|
|
|
|
2024-08-19 10:01:07 +05:00
|
|
|
var memoryStream = new MemoryStream();
|
|
|
|
stream?.CopyTo(memoryStream);
|
|
|
|
memoryStream.Position = 0;
|
2024-07-04 11:02:45 +05:00
|
|
|
|
2024-07-08 11:09:43 +05:00
|
|
|
return memoryStream;
|
|
|
|
}
|
2024-08-19 10:01:07 +05:00
|
|
|
}
|