确定是否在ResourceManager中存在资源 [英] Determine if a resource exists in ResourceManager

查看:101
本文介绍了确定是否在ResourceManager中存在资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

反正是有,以确定是否一个ResourceManager包含一个名为资源?目前,我抓住MissingManifestResourceException但我讨厌不得不使用非特殊情况下例外。 ?必须有某种方式通过反射,或一些列举一个ResourceManager的名称值对

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?

修改:更详细一点。资源是不是在执行程序集,但是,ResourceManager会工作得很好。如果我尝试 _resourceMan.GetResourceSet(_defaultCuture,假,真)我得到空,而如果我尝试 _resourceMan.GetString(StringExists)我得到一个字符串返回。

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.

推荐答案

您可以使用的ResourceSet要做到这一点,只有它加载所有数据到内存中,如果你列举了。这里y'go:

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

这篇关于确定是否在ResourceManager中存在资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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