问题
For my translations I'm making use of embedded .resx files. Some of these translations I wish to override with another .resx file, which is not embedded (ex. ~/App_Localresources/translations.en-US.resx).
The purpose of this is that after the application is compiled and deployed, a user could change the .resx file manually to override some of the embedded translations.
Is there a way to use the normal ResourceManager for this? (in .NET 4)
Thank you for tips
回答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");
}
}
来源:https://stackoverflow.com/questions/3405877/asp-net-resourcemanager-to-read-local-resx