使用动态文件名读取存储在资源文件(resx)中的字符串 [英] Read a string stored in a resource file (resx) with dynamic file name

查看:157
本文介绍了使用动态文件名读取存储在资源文件(resx)中的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想要做的是避免每次重新编译整个项目我必须向我的客户提供我的应用程序,所以我需要动态访问这个字符串。
那么,如果我只在执行时刻删除文件名,我该如何访问(在应用执行期间)到一个resx文件?



从现在开始写一些类似的东西:

  Properties.Resources.MyString1 

其中Resource是我的Resource.resx文件。
但是我需要这样的东西:

  GetStringFromDynamicResourceFile(MyFile.resx,MyString1); 

可以吗?



感谢
标记

解决方案

你的情况下会有什么帮助吗?

 字典< string,string> resourceMap = new Dictionary< string,string>(); 

public static void Func(string fileName)
{
ResXResourceReader rsxr = new ResXResourceReader(fileName);
foreach(rsxr中的DictionaryEntry d)
{
resourceMap.Add(d.Key.ToString(),d.Value.ToString());
}
rsxr.Close();
}

public string GetResource(string resourceId)
{
return resourceMap [resourceId];
}


In my C# application I need to create a .resx file of strings customized for every customer.

What I want to do is avoid recompiling the entire project every time I have to provide my application to my customer, so I need to dynamic access to this string. So, how can I access (during the app execution) to a resx file if I kwow the file name only on the execution time?

Since now I write something similar:

Properties.Resources.MyString1

where Resource is my Resource.resx file. But I need something like this:

GetStringFromDynamicResourceFile("MyFile.resx", "MyString1");

Is it possible?

Thanks Mark

解决方案

Will something like this help in your case?

Dictionary<string, string> resourceMap = new Dictionary<string, string>();

public static void Func(string fileName)
{
    ResXResourceReader rsxr = new ResXResourceReader(fileName);        
    foreach (DictionaryEntry d in rsxr)
    {
        resourceMap.Add(d.Key.ToString(),d.Value.ToString());           
    }        
    rsxr.Close();
}

public string GetResource(string resourceId)
{
    return resourceMap[resourceId];
}

这篇关于使用动态文件名读取存储在资源文件(resx)中的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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