forked from pauldotknopf/JavaScriptViewEngine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtils.cs
More file actions
37 lines (32 loc) · 1.17 KB
/
Utils.cs
File metadata and controls
37 lines (32 loc) · 1.17 KB
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
36
37
using System;
using System.IO;
using System.Reflection;
using System.Text;
namespace JavaScriptViewEngine
{
internal static class Utils
{
public static string GetResourceAsString(string resourceName, Type type)
{
var assembly = type.Assembly;
return GetResourceAsString(resourceName, assembly);
}
public static string GetResourceAsString(string resourceName, Assembly assembly)
{
using (Stream stream = assembly.GetManifestResourceStream(resourceName))
{
if (stream == null)
throw new NullReferenceException(string.Format("No resource found for " + resourceName));
using (var reader = new StreamReader(stream))
return reader.ReadToEnd();
}
}
public static string GetFileTextContent(string path, Encoding encoding = null)
{
if (!File.Exists(path))
throw new FileNotFoundException(path);
using (var file = new StreamReader(path, encoding ?? Encoding.UTF8))
return file.ReadToEnd();
}
}
}