15

我需要编写一个程序,从 dll 中读取所有字符串资源并将它们插入到某个表中。我有读取资源的方法:

    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);
            }
        }
    }

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

如何忽略作为“文件”添加的资源并只读字符串?

4

1 回答 1

3

没有办法做到这一点。例如,通过 Reflector 查看您程序集的资源部分。您的文本文件保存为字符串。字符串值和文本文件值之间没有区别。

但是,二进制文件不会成为问题,因为对于二进制文件类型,您将 byte[] 作为值而不是字符串。

于 2011-06-30T08:48:54.013 回答