82289

Reverse a ResourceManager

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

Answer1:

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

Recommend

  • Dagger 2 How to inject one class to multiple components using Sub components?
  • Analyzing XML schemas using org.eclipse.xsd and Maven2
  • Get all resources in array
  • How to insert variables to dat.Gui with an array?
  • wxPython: How to get sizer from wx.StaticText?
  • Haskell: List Created Evaluating List Elements
  • Fiddler is not showing HTTPS traffic
  • .NET compiled third-party DLL reference conflict
  • Counterintuitive design of addition/subtraction between numbers and nullable numbers [closed]
  • How can I get the “Edit Component's Name” window to show when I place a component?
  • JAR file: Could not find main class
  • Delphi: StringGrid, position and Context Menu
  • reduce/reduce conflicts using ocamlyacc
  • How to write string.Contains(someText) in expression Tree
  • How to get the index of element in the List in c#
  • how to remove a div with same ids but display='block' and display='none' in JAVa
  • Rails AREL .where statement
  • LNK1104: cannot open file 'kernel32.lib'
  • Get localized short date pattern as String?
  • Can my PDF ping my server when it is opened?
  • Using $compile in a directive triggers AngularJS infinite digest error
  • How to programatically 'login' a user based on 'remember me' cookie when using j
  • Pycharm: Marking a folder as 'sources root' is not recursive for subfolders
  • msbuild create itemgroup from property group
  • Updating both a ConcurrentHashMap and an AtomicInteger safely
  • Multicolored edittext hint
  • Copy to all folders batch file?
  • x64 applications using gdi+: what are the consequences on performance?
  • Why is the size of this struct 32?
  • Read text file and split every line in MSBuild
  • Convert array of 8 bytes to signed long in C++
  • Return words with double consecutive letters
  • how to add data labels for bar graph in matlab
  • Understanding cpu registers
  • Django query for large number of relationships
  • Recursive/Hierarchical Query Using Postgres
  • Running Map reduces the dimensions of the matrices
  • Why is Django giving me: 'first_name' is an invalid keyword argument for this function?
  • How can I use `wmic` in a Windows PE script?
  • How to push additional view controllers onto NavigationController but keep the TabBar?