-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathResource.cs
More file actions
36 lines (34 loc) · 1.05 KB
/
Resource.cs
File metadata and controls
36 lines (34 loc) · 1.05 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
using System;
using System.Reflection;
using System.IO;
namespace CopyDb
{
public class Resource
{
public static string LoadString (string resourcename)
{
Assembly asm = Assembly.GetCallingAssembly();
return LoadString(asm.GetName().Name + "." + resourcename, asm);
}
public static string LoadString (string resourcename, Assembly asm)
{
if (asm == null)
throw (new System.ArgumentNullException("asm"));
using (Stream resourcestream = asm.GetManifestResourceStream(resourcename))
{
if (resourcestream == null)
throw new System.Resources.MissingManifestResourceException(resourcename);
using (StreamReader reader = new StreamReader(resourcestream))
return reader.ReadToEnd();
}
}
public static string LoadClassString (string name, Type classtype)
{
if (classtype == null)
throw (new System.ArgumentNullException("classtype"));
string resourcename = classtype.FullName + "." + name;
Assembly asm = classtype.Assembly;
return LoadString(resourcename, asm);
}
}
}