private static Hashtable _asmfiles;
public static byte[] LoadAssemblyFiles(string filename)
{
if (filename == null)
{
throw new ArgumentNullException("filename");
}
if (!filename.StartsWith("/"))
{
throw new ArgumentException("must starts with '/'", "filename");
}
filename = "/" + filename.Remove(0, 1).Replace('/', '.');
if (Resx._asmfiles == null)
{
Hashtable afs = new Hashtable();
foreach (string resname in typeof(Resx).Assembly.GetManifestResourceNames())
{
if (resname.StartsWith("UploadFileHelper.Uploader.File."))
{
byte[] buf;
string fn = "/" + resname.Remove(0, "UploadFileHelper.Uploader.File.".Length);
fn = fn.ToLower();
using (Stream s = typeof(Resx).Assembly.GetManifestResourceStream(resname))
{
buf = new byte[s.Length];
s.Read(buf, 0, buf.Length);
}
afs.Add(fn, buf);
}
}
Resx._asmfiles = afs;
}
return (byte[]) Resx._asmfiles[filename.ToLower()];
}
本文介绍了一种从程序资源中加载特定文件的方法,并详细解释了如何通过反射获取程序集中的资源文件,以及如何处理这些资源文件。文章还提供了一个具体的示例方法,用于根据给定的文件名加载字节数据。

645

被折叠的 条评论
为什么被折叠?



