forked from ddrilling/AsbCloudServer
Рфеакторинг метода расширения получения файла из сборки
This commit is contained in:
parent
96a8c3fbd3
commit
3865c330c2
@ -1,9 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Text;
|
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@ -11,7 +9,29 @@ namespace AsbCloudInfrastructure
|
|||||||
{
|
{
|
||||||
public static class AssemblyExtensions
|
public static class AssemblyExtensions
|
||||||
{
|
{
|
||||||
public static async Task<Stream> GetTemplateCopyStreamAsync(this Assembly assembly, string templateName, CancellationToken cancellationToken)
|
public static Stream GetTemplateCopyStream(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;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Obsolete]
|
||||||
|
public static async Task<Stream> GetTemplateCopyStreamAsync(this Assembly assembly,
|
||||||
|
string templateName,
|
||||||
|
CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
var resourceName = assembly
|
var resourceName = assembly
|
||||||
.GetManifestResourceNames()
|
.GetManifestResourceNames()
|
||||||
|
Loading…
Reference in New Issue
Block a user