ourceManager的覆盖GetResourceFileNa

ourceManager的覆盖GetResourceFileNa

本文介绍了ResourceManager的覆盖GetResourceFileName的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要重写在mscorlib程序V4的System.Resources.ResourceManager类中的方法

I want to override a method in the System.Resources.ResourceManager class in mscorlib v4.

我要重写这样的方法GetResourceFileName;

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");
    }



现在的问题是,以实例化一个ResourceManager类的,我必须使用静态方法CreateFileBasedResourceManager ,它返回的ResourceManager的新实例。 (因为我需要的文件依据的ResourceManager)

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)

我怎么可以重写此方法?我也试图调用私有构造函数调用CreateFileBasedResourceManager来创建对象,但我得到这个异​​常(不能援引与反思私有构造?);

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


推荐答案

创建您自己的资源提供者,并在您的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

这篇关于ResourceManager的覆盖GetResourceFileName的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 04:54