0 Comments

If you want to get all resource string keys of resource string values from an embeded resource file in C# you can use this function:
(if the embeded resoure file contains a resourestring with key=[EmptyParameter] and value [This is an empty parameter], this function will return a generic List<string> with one value [EmptyParameter]

public static List<string> GetAllResourceStrings(ResourceFileNames resourceFileNames)
       {
           List<string> resourceStrings = new List<string>();
           FieldInfo[] fields = null;
           ResourceSet resourceSet = null;
           switch (resourceFileNames)
           {
               case ResourceFileNames.Exception:
                   resourceSet = ExceptionResources.ResourceManager.GetResourceSet(CultureInfo.CurrentCulture, true, true);
                   break;
               case ResourceFileNames.Gui:
                   resourceSet = GuiResources.ResourceManager.GetResourceSet(CultureInfo.CurrentCulture, true, true);
                   break;
           }
           IDictionaryEnumerator enumerator = resourceSet.GetEnumerator();
           while (enumerator.MoveNext())
           {
               resourceStrings.Add(enumerator.Key.ToString());
           }
           return resourceStrings;
       }

(ResourceFileNames resourceFileNames = a custom enumeration)

(ExceptionResources is the class generated by visual studio for the embeded resource file ExceptionResources.resx)

(GuiResourcesis the class generated by visual studio for the embeded resource file ExceptionResources.resx)

One Reply to “List all resource string keys with a ResourceManger from an embeded resource file in C#

  1. It would be great if you would tell us what your “custom enumeration” was for the example… And maybe even all the namespaces you were using… Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.