Is there anyway to determine if a ResourceManager contains a named resource? Currently I am catching the MissingManifestResourceException but I hate having to use Exceptions for non-exceptional situations. There must be some way to enumerate the name value pairs of a ResourceManager through reflection, or something?
EDIT: A little more detail. The resources are not in executing assembly, however the ResourceManager is working just fine. If I try _resourceMan.GetResourceSet(_defaultCuture, false, true)
I get null, whereas if I try _resourceMan.GetString("StringExists")
I get a string back.
You can use the ResourceSet to do that, only it loads all the data into memory if you enumerate it. Here y'go:
// At startup.
ResourceManager mgr = Resources.ResourceManager;
List<string> keys = new List<string>();
ResourceSet set = mgr.GetResourceSet(CultureInfo.CurrentCulture, true, true);
foreach (DictionaryEntry o in set)
{
keys.Add((string)o.Key);
}
mgr.ReleaseAllResources();
Console.WriteLine(Resources.A);
I think you can use something like Assembly.GetManifestResourceNames to enumerate the list of resources available in the Assembly's manifest. It isn't pretty and doesn't solve all of the corner cases, but works if required.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With