问题
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)?
回答1:
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;
}
来源:https://stackoverflow.com/questions/563506/reverse-a-resourcemanager