22 May, 2009
0 Comments
0 categories
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)
Tags: C#
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!