WPF - check resource exists without structured exception handling

后端 未结 1 1158
既然无缘
既然无缘 2021-02-04 20:06

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\'

相关标签:
1条回答
  • 2021-02-04 20:27

    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);
    }
    
    0 讨论(0)
提交回复
热议问题