Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF - check resource exists without structured exception handling

Is there any way to check if a resource exists in an assembly without having to use exception handling? I'm currently loading images from several assemblies, and if they don't exist then I'm handling the IOException, which causes quite a bit of overhead.

like image 877
devdigital Avatar asked Jan 18 '11 11:01

devdigital


1 Answers

Would something like this work for you?

// Member Variable
string [] resourceNames;

// Function
Boolean ResourceExists(string resourceName)
{
    if (resourceNames == null)
    {
        resourceNames =  
            Assembly.GetExecutingAssembly().GetManifestResourceNames(); 
    }

    return resourceNames.Contains(resourceName);
}
like image 102
Wonko the Sane Avatar answered Nov 15 '22 07:11

Wonko the Sane