Guest User

Untitled

a guest
Oct 18th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. using System.Collections;
  2. using System.Globalization;
  3. using System.Resources;
  4.  
  5. ...
  6.  
  7. ResourceSet resourceSet = MyResourceClass.ResourceManager.GetResourceSet(CultureInfo.CurrentUICulture, true, true);
  8. foreach (DictionaryEntry entry in resourceSet)
  9. {
  10. string resourceKey = entry.Key.ToString();
  11. object resource = entry.Value;
  12. }
  13.  
  14. var assembly = Assembly.GetExecutingAssembly();
  15.  
  16. foreach (var resourceName in assembly.GetManifestResourceNames())
  17. System.Console.WriteLine(resourceName);
  18.  
  19. foreach (var resourceName in assembly.GetManifestResourceNames())
  20. {
  21. using(var stream = assembly.GetManifestResourceStream(resourceName))
  22. {
  23. // Do something with stream
  24. }
  25. }
  26.  
  27. ResXResourceReader rsxr = new ResXResourceReader("your resource file path");
  28.  
  29. // Iterate through the resources and display the contents to the console.
  30. foreach (DictionaryEntry d in rsxr)
  31. {
  32. Console.WriteLine(d.Key.ToString() + ":t" + d.Value.ToString());
  33. }
  34.  
  35. // Create a ResXResourceReader for the file items.resx.
  36. ResXResourceReader rsxr = new ResXResourceReader("items.resx");
  37.  
  38. // Create an IDictionaryEnumerator to iterate through the resources.
  39. IDictionaryEnumerator id = rsxr.GetEnumerator();
  40.  
  41. // Iterate through the resources and display the contents to the console.
  42. foreach (DictionaryEntry d in rsxr)
  43. {
  44. Console.WriteLine(d.Key.ToString() + ":t" + d.Value.ToString());
  45. }
  46.  
  47. //Close the reader.
  48. rsxr.Close();
  49.  
  50. Type resourceType = Type.GetType("AssemblyName.Resource1");
  51. PropertyInfo[] resourceProps = resourceType.GetProperties(
  52. BindingFlags.NonPublic |
  53. BindingFlags.Static |
  54. BindingFlags.GetProperty);
  55.  
  56. foreach (PropertyInfo info in resourceProps)
  57. {
  58. string name = info.Name;
  59. object value = info.GetValue(null, null); // object can be an image, a string whatever
  60. // do something with name and value
  61. }
  62.  
  63. XDocument
  64. .Load(resxFileName)
  65. .Descendants()
  66. .Where(_ => _.Name == "data")
  67. .Select(_ => $"{ _.Attributes().First(a => a.Name == "name").Value} - {_.Value}");
  68.  
  69. ResourceSet resourceSet =
  70. Resources.ResourceManager.GetResourceSet(CultureInfo.CurrentUICulture, true, true);
  71. foreach (var entry in resourceSet.OfType<DictionaryEntry>().Select((item, i) => new { Index = i, Key = item.Key, Value = item.Value }))
  72. {
  73. Console.WriteLine(@"[{0}] {1}", entry.Index, entry.Key);
  74. }
Add Comment
Please, Sign In to add comment