C# ASP.NET Resourcemanager读取本地.resx
对于我的翻译,我使用嵌入的.resx文件。我希望用另一个未嵌入的.resx文件覆盖其中一些翻译(例如~/App\u Localresources/translations.en US.resx) 这样做的目的是,在编译和部署应用程序后,用户可以手动更改.resx文件以覆盖某些嵌入的翻译 有没有办法使用普通的ResourceManager来实现这一点?(在.NET 4中)C# ASP.NET Resourcemanager读取本地.resx,c#,asp.net,c#-4.0,resx,C#,Asp.net,C# 4.0,Resx,对于我的翻译,我使用嵌入的.resx文件。我希望用另一个未嵌入的.resx文件覆盖其中一些翻译(例如~/App\u Localresources/translations.en US.resx) 这样做的目的是,在编译和部署应用程序后,用户可以手动更改.resx文件以覆盖某些嵌入的翻译 有没有办法使用普通的ResourceManager来实现这一点?(在.NET 4中) 谢谢你的提示你如何使用这个?你能举个例子吗?谢谢,我找了一段时间了。使用示例:ResxResourceManager rm=n
谢谢你的提示你如何使用这个?你能举个例子吗?谢谢,我找了一段时间了。使用示例:ResxResourceManager rm=new ResxResourceManager(“源文件名”、“路径资源目录”);rm.GetString(名称,System.Globalization.CultureInfo.GetCultureInfo(“en-US”))代码>此代码似乎非常危险。它正在使用refelction调用自身的第二个基本构造函数。而且该构造函数是公共的(并且从.NET2开始就一直是公共的:可能它不在.NET1或1.1中?)。
public class ResxResourceManager : System.Resources.ResourceManager {
public ResxResourceManager(string baseName, string resourceDir) {
Type[] paramTypes = new Type[] { typeof(string), typeof(string), typeof(Type) };
object[] paramValues = new object[] { baseName, resourceDir, typeof(ResXResourceSet) };
Type baseType = GetType().BaseType;
ConstructorInfo ci = baseType.GetConstructor(
BindingFlags.Instance | BindingFlags.NonPublic,
null, paramTypes, null);
ci.Invoke(this, paramValues);
}
protected override string GetResourceFileName(CultureInfo culture) {
string resourceFileName = base.GetResourceFileName(culture);
return resourceFileName.Replace(".resources", ".resx");
}
}