Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get all strings from resourcemanager

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?

like image 434
Oleksey Avatar asked Jun 30 '11 07:06

Oleksey


1 Answers

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.

like image 134
DiVan Avatar answered Oct 17 '22 02:10

DiVan