forked from npgsql/npgsql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmbeddedResource.cs
More file actions
27 lines (23 loc) · 815 Bytes
/
EmbeddedResource.cs
File metadata and controls
27 lines (23 loc) · 815 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
using System;
using System.IO;
using System.Reflection;
namespace Npgsql.SourceGenerators
{
static class EmbeddedResource
{
public static string GetContent(string relativePath)
{
var baseName = Assembly.GetExecutingAssembly().GetName().Name;
var resourceName = relativePath
.TrimStart('.')
.Replace(Path.DirectorySeparatorChar, '.')
.Replace(Path.AltDirectorySeparatorChar, '.');
using var stream = Assembly.GetExecutingAssembly()
.GetManifestResourceStream(baseName + "." + resourceName);
if (stream == null)
throw new NotSupportedException();
using var reader = new StreamReader(stream);
return reader.ReadToEnd();
}
}
}