在我的 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];
}
关于c# - 使用动态文件名读取存储在资源文件 (resx) 中的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1097154/