15

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?

Oleksey
  • 151
  • 1
  • 3

1 Answers1

3

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.

DiVan
  • 381
  • 2
  • 6
  • yes, binary files is not a problem. Problem only with text files. But when i'm watching the resources in Visual Studio 2010, they are sorted by type: "Strings"\"Files"\"Images"\"Icons". How they are doing that? – Oleksey Jun 30 '11 at 11:55
  • These are resource representation of Visual Studio. It uses files and pictures and icons locations to load them as resources into assembly. After that, you have only assembly with bitmap, string or byte[] data. – DiVan Jun 30 '11 at 14:37