如何从资源程序集中读取资源(例如microsoft.visualbasic.resources.dll) [英] how to read resources from a resource assembly (such as microsoft.visualbasic.resources.dll)

查看:60
本文介绍了如何从资源程序集中读取资源(例如microsoft.visualbasic.resources.dll)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编写一个从资源程序集中检索资源名称和值的方法.

MSDN显示如下.但似乎这仅适用于xxx.resources文件,但不适用于资源组装.当我调试它时,它抛出异常,即流不是有效文件.


I want to write a method that retrieves the resource name and value from a resource assembly.

MSDN shows below. but it seems like this works only for xxx.resources file, but not on resource assembly. when I debug this, it throws exception that stream is not a valid file.


IResourceReader reader = new ResourceReader("d:\work\Microsoft.visualbasic.resources.dll");
IDictionaryEnumerator en = reader.GetEnumerator();
while (en.MoveNext()) {
   Console.WriteLine();
   Console.WriteLine("Name: {0}", en.Key);
   Console.WriteLine("Value: {0}", en.Value);
}
reader.Close();




有谁知道如何在resourcereader中指定文件或它支持的文件类型?




does anyone know how to specify the file in the resourcereader or what file types it supports?

推荐答案

ResourceReader [您可以使用资源读取器从.resources文件中读取资源名称和资源值对.
You can use resource readers to read resource name and resource value pairs from .resources files.

,所以恐怕您的代码将无法正常工作.

如果您阅读
[

, so I''m afraid that your code won''t work.

If you read this[^] article you should get some ideas on how to do what you want using P/Invoke, which is the only way that I know of to do so.


ResourceManager resourceManager = new ResourceManager("Resources.RegExResource,Assembly.GetAssembly(typeof(Resources.RegExResource)));
ResourceSet rs = resourceManager.GetResourceSet(CultureInfo.CurrentCulture,true,true);
foreach(rs中的DictionaryEntry d)
{
Console.WriteLine(d.Key.ToString()+:\ t" + d.Value.ToString());
}
ResourceManager resourceManager = new ResourceManager("Resources.RegExResource", Assembly.GetAssembly(typeof(Resources.RegExResource)));
ResourceSet rs=resourceManager.GetResourceSet(CultureInfo.CurrentCulture, true, true);
foreach (DictionaryEntry d in rs)
{
Console.WriteLine(d.Key.ToString() + ":\t" + d.Value.ToString());
}


这篇关于如何从资源程序集中读取资源(例如microsoft.visualbasic.resources.dll)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆