Question

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.

Was it helpful?

Solution

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);

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top