foreach string resourceKey in ResourceManager?

  • Thread starter Thread starter deerchao
  • Start date Start date
D

deerchao

Is there any way I can get all resource keys with in a compiled and
embedded resx file?
Thanks!
 
deerchao said:
Is there any way I can get all resource keys with in a compiled and
embedded resx file?
Thanks!

This can be done by enumerating the keys of the underlying ResourceSet. See
below for a sample function (C# 2.0 and later).

private IEnumerable<string> GetResourceNames(string name)
{
return GetResourceNames(name, Assembly.GetExecutingAssembly());
}

private IEnumerable<string> GetResourceNames(string name, Assembly assembly)
{
ResourceManager rm = new ResourceManager(name, assembly);
ResourceSet rs = rm.GetResourceSet(CultureInfo.CurrentUICulture, true,
true);

IDictionaryEnumerator ide = rs.GetEnumerator();

while (ide.MoveNext())
{
yield return (string)ide.Key;
}
}

Sample code:
foreach (string key in GetResourceNames("RD.Properties.Resources")) // This
is the fully qualified name of the resource set
{
// Do something with key...
}

Best Regards,
Stanimir Stoyanov
www.stoyanoff.info | www.aeroxp.org
 
Back
Top