Get all strings from resourcemanager

可紊 提交于 2019-12-21 07:38:13

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/6531677/get-all-strings-from-resourcemanager

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!