在我的C#应用程序中,我需要为每个客户创建一个定制的.resx文件.
我想要做的是避免每次我将应用程序提供给我的客户时重新编译整个项目,所以我需要动态地访问这个字符串.
那么,如果只在执行时刻删除文件名,那么如何访问(在应用程序执行期间)到一个resx文件?
从此以后我写的东西类似:
- Properties.Resources.MyString1
其中Resource是我的Resource.resx文件.
但我需要这样的东西:
- GetStringFromDynamicResourceFile("MyFile.resx","MyString1");
可能吗?
谢谢
标记
解决方法
你的情况下会有这样的帮助吗?
- 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];
- }