反转一个ResourceManager [英] Reverse a ResourceManager

查看:117
本文介绍了反转一个ResourceManager的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果你这样做ResourceManager.GetString(键),你可以得到一个项目,在资源的价值。有没有办法做一个反向查找来从给定的值(基本上取消转换)资源的关键?

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)?

推荐答案

您应该能够得到ResourceSet的和迭代它的价值和回报的关键,如果他们是平等的。只要记住,你需要比较值,而不是引用。这些方针的东西(不编译和测试,但类似的东西)

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;
  }

这篇关于反转一个ResourceManager的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆