得到ResourceManager中的所有字符串 [英] Get all strings from resourcemanager

查看:149
本文介绍了得到ResourceManager中的所有字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要编写一个程序,从DLL读取所有字符串资源,并将其插入到一些表。我有方法,即读取资源:

I need to write a program, that reads all string resources from dll and insert them into some table. I have the method, that reads resources:

    private static IEnumerable<KeyValuePair<string,string>> getAllResources(ResourceManager resourceManager, 
        Language language)
    {

        ResourceSet resourceSet = resourceManager.GetResourceSet(getCulture(language), true, true);

        IDictionaryEnumerator dictNumerator = resourceSet.GetEnumerator();

        // Get all string resources
        while (dictNumerator.MoveNext())
        {
            // Only string resources
            if (dictNumerator.Value is string)
            {
                var key = (string)dictNumerator.Key;
                var value = (string)dictNumerator.Value;
                yield return new KeyValuePair<string, string>(key, value);
            }
        }
    }



但是,当我开始使用它我注意到,它也读出资源,像文件添加(读取文件内容)

But when I started using it, I noticed that it also reads the resources, that added like a file (reads file content)

我怎么能忽略添加为文件的资源,只读字符串?

How can I ignore resources that are added as a "file", and read only strings?

推荐答案

有没有这样做的方式。
,看一下你的资源部分通过反射镜组合,例如。您的文本文件保存为字符串。有字符串值和文本文件值之间没有差异。

There is no way of doing that. Have a look to the resource section of you assembly through Reflector, for instance. Your text file is saved as String. There is no difference between String value and Text File value.

二进制文件,但是,将不会是一个问题,因为二进制文件类型,你就会有一个字节[作为值,而不是字符串。

Binary files, however, won't be a problem, as for binary file types you'll have byte[] as value and not string.

这篇关于得到ResourceManager中的所有字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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