gpt4 book ai didi

.net - 反转 ResourceManager

转载 作者:行者123 更新时间:2023-12-01 13:08:58 30 4
gpt4 key购买 nike

如果执行 ResourceManager.GetString(Key),您可以获取资源中某个项目的值。有没有一种方法可以进行反向查找以从给定值的资源中获取 key (本质上是反翻译)?

最佳答案

您应该能够获取 ResourceSet 并迭代它的值,如果它们相等则返回键。请记住,您需要比较值,而不是引用。类似的东西(没有编译和测试,但类似)

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

关于.net - 反转 ResourceManager,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/563506/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com