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.
精彩评论