ResourceManager 覆盖 GetResourceFileName
我想重写 mscorlib v4 中 System.Resources.ResourceManager 类中的方法。
我想像这样重写 GetResourceFileName 方法;
protected override string GetResourceFileName(CultureInfo culture) {
string resourceFileName = base.GetResourceFileName(culture);
return resourceFileName.Replace(".resources", ".resx");
}
问题是,要实例化 ResourceManager 类,我必须使用静态方法 CreateFileBasedResourceManager,它返回 ResourceManager 的新实例。 (因为我需要基于文件的资源管理器)
我如何覆盖这个方法?我还尝试调用私有构造函数 CreateFileBasedResourceManager 调用来创建对象,但我收到此异常(无法使用反射调用私有构造函数?);
[SecurityException: Request failed.]
System.RuntimeMethodHandle.PerformSecurityCheck(Object obj, RuntimeMethodHandleInternal method, RuntimeType parent, UInt32 invocationFlags) +0
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) +323
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +38
System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) +35
System.Xml.Xsl.XsltOld.FuncExtension.Invoke(XsltContext xsltContext, Object[] args, XPathNavigator docContext) +164
MS.Internal.Xml.XPath.FunctionQuery.Evaluate(XPathNodeIterator nodeIterator) +430
I want to override a method in the System.Resources.ResourceManager class in mscorlib v4.
I want to override the method GetResourceFileName like this;
protected override string GetResourceFileName(CultureInfo culture) {
string resourceFileName = base.GetResourceFileName(culture);
return resourceFileName.Replace(".resources", ".resx");
}
The problem is, to instanciate a ResourceManager class I must use the static method CreateFileBasedResourceManager, which returns a new instance of the ResourceManager. (because I need the file based resourcemanager)
How can I override this method? I also tried to call the private constructor CreateFileBasedResourceManager calls to create the object, but i'm getting this exception (can't invoke private constructor with reflection?);
[SecurityException: Request failed.]
System.RuntimeMethodHandle.PerformSecurityCheck(Object obj, RuntimeMethodHandleInternal method, RuntimeType parent, UInt32 invocationFlags) +0
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) +323
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +38
System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) +35
System.Xml.Xsl.XsltOld.FuncExtension.Invoke(XsltContext xsltContext, Object[] args, XPathNavigator docContext) +164
MS.Internal.Xml.XPath.FunctionQuery.Evaluate(XPathNodeIterator nodeIterator) +430
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
创建您自己的资源提供程序并在您的 app.config 或 web.config 中引用它。可以在此处找到示例
Create your own resource provider and reference it in your app.config or web.config. An example can be found here