-
Notifications
You must be signed in to change notification settings - Fork 9.8k
/
EmbeddedResourceReader.cs
35 lines (32 loc) · 1.37 KB
/
EmbeddedResourceReader.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.IO;
using System.Reflection;
namespace Microsoft.AspNetCore.NodeServices
{
/// <summary>
/// Contains methods for reading embedded resources.
/// </summary>
[Obsolete("Use Microsoft.AspNetCore.SpaServices.Extensions")]
public static class EmbeddedResourceReader
{
/// <summary>
/// Reads the specified embedded resource from a given assembly.
/// </summary>
/// <param name="assemblyContainingType">Any <see cref="Type"/> in the assembly whose resource is to be read.</param>
/// <param name="path">The path of the resource to be read.</param>
/// <returns>The contents of the resource.</returns>
[Obsolete("Use Microsoft.AspNetCore.SpaServices.Extensions")]
public static string Read(Type assemblyContainingType, string path)
{
var asm = assemblyContainingType.GetTypeInfo().Assembly;
var embeddedResourceName = asm.GetName().Name + path.Replace("/", ".");
using (var stream = asm.GetManifestResourceStream(embeddedResourceName))
using (var sr = new StreamReader(stream))
{
return sr.ReadToEnd();
}
}
}
}