I have this code

new ResourceManager(base_name, this.TargetType.Assembly).GetString(base.DisplayNameValue); 

taken in try-catch. The likelihood that the resource will not be, and will require an alternative method of obtaining a result is great. When a lot of calls to non-existent resources, the program slows down.

How to check resource availability before trying to get it?

    2 answers 2

    Since, if there is no resource, it is unlikely to appear in the future, you can memorize resources in HashMap, the calls for which gave an error and at subsequent calls to them immediately use alternative methods. This method will help if there is frequent repeated access to the same resources. You can use this method differently, for example, when you start the program, immediately collect a list of available resources and then dance from it.

    • No, not the case. Often there is no re. - Modus

    You can try to get a list of all resource lines in the assembly using Assembly.GetManifestResourceNames and, already relying on it, select existing ones.

    • base_name in the given code example is taken from there. The question is how to check it in more detail. - Modus