WPF - 检查资源不存在结构化异常处理 [英] WPF - check resource exists without structured exception handling

查看:168
本文介绍了WPF - 检查资源不存在结构化异常处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有什么办法来检查装配体中的一个资源存在,而无需使用异常处理?我目前正在加载的图像来自几个组件,如果他们不存在,那么我处理IOException异常,导致相当多的开销。

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.

推荐答案

请问这样的事情对你的工作?

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

这篇关于WPF - 检查资源不存在结构化异常处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆