-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathResourceHelper.cs
More file actions
33 lines (29 loc) · 1011 Bytes
/
Copy pathResourceHelper.cs
File metadata and controls
33 lines (29 loc) · 1011 Bytes
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
using System.IO;
using System.Reflection;
namespace UCNLSalinity
{
internal static class ResourceHelper
{
public static Stream GetResourceStream(string resourceName)
{
var assembly = Assembly.GetExecutingAssembly();
var fullResourceName = $"UCNLSalinity.{resourceName}";
var stream = assembly.GetManifestResourceStream(fullResourceName);
if (stream == null)
{
var names = assembly.GetManifestResourceNames();
throw new FileNotFoundException(
$"Resource '{fullResourceName}' not found. Available: {string.Join(", ", names)}");
}
return stream;
}
public static string GetResourceAsString(string resourceName)
{
using (var stream = GetResourceStream(resourceName))
using (var reader = new StreamReader(stream))
{
return reader.ReadToEnd();
}
}
}
}