If you do ResourceManager.GetString(Key), you can get the value of an item in a resource. Is there a way to do a reverse lookup to get the key from the resource given the value (essentially de-translate)?
+4
A:
You should be able to get the ResourceSet and iterate over it's values and return the key if they are equal. Just remember, you need to compare values, not references. Something along these lines (Not compiled and tested, but something similar)
System.Resources.ResourceManager rm =
new System.Resources.ResourceManager("MyAssembly.MyResources",
System.Reflection.Assembly.GetExecutingAssembly());
System.Resources.ResourceSet rs =
rm.GetResourceSet(System.Globalization.CultureInfo.CurrentCulture,
false, false);
System.Collections.IDictionaryEnumerator ide = rs.GetEnumerator();
while(ide.MoveNext())
{
if (ide.Value == val)
return ide.Key;
}
Mystere Man
2009-02-19 01:33:29
When I do this, I get back a null ResourceSet. Any ideas?
brian
2009-02-19 15:42:30
I changed both the bool parameters in GetResourceSet to true and it worked. Thanks!
brian
2009-02-19 18:16:35