我找到了如何从.resx文件中读取的这个例子
public static void ReadResourceFile()
{
ResourceManager rm = new ResourceManager("XmlReadAndWritePractice.Resource1", Assembly.GetExecutingAssembly());
//String strWebsite = rm.GetString("Website",CultureInfo.CurrentCulture);
String strName = rm.GetString("FirstName");
Console.WriteLine(strName);
}
但是如何编辑或添加.resx文件?我发现了以下示例,但它并不是我所期待的。
private static void CreateResourceFile()
{
// Creates a resource writer.
IResourceWriter writer = new ResourceWriter("c:\\temp\\Resource1.resx");
// Adds resources to the resource writer.
writer.AddResource("String 1", "First String");
writer.AddResource("String 2", "Second String");
writer.AddResource("String 3", "Third String");
// Writes the resources to the file or stream, and closes it.
writer.Close();
}
资源参考
答案 0 :(得分:1)
您需要在收盘前调用生成。
writer.Generate();
writer.Close();
答案 1 :(得分:1)
答案 2 :(得分:1)
private static void CreateResourceFile()
{
using (ResXResourceWriter writer = new ResXResourceWriter("c:\\temp\\Resource1.resx"))
{
writer.AddResource("String 1", "First String");
writer.AddResource("String 2", "Second String");
writer.AddResource("String 3", "Third String");
writer.Generate();
}
}