在我的C#应用程序中,我需要创建一个为每个客户定制的字符串.resx文件.
我想要做的是每次我必须向我的客户提供我的应用程序时避免重新编译整个项目,所以我需要动态访问这个字符串.那么,如果我只在执行时间记录文件名,我如何访问(在应用程序执行期间)resx文件?
从现在起我写了类似的东西:
Properties.Resources.MyString1
Run Code Online (Sandbox Code Playgroud)
其中Resource是我的Resource.resx文件.但是我需要这样的东西:
GetStringFromDynamicResourceFile("MyFile.resx", "MyString1");
Run Code Online (Sandbox Code Playgroud)
可能吗?
谢谢马克
Pra*_*nth 13
在你的情况下,这样的事情会有帮助吗?
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];
}
Run Code Online (Sandbox Code Playgroud)