ResourceManager override GetResourceFileName

喜你入骨 提交于 2019-12-11 06:57:14

问题


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

回答1:


Create your own resource provider and reference it in your app.config or web.config. An example can be found here



来源:https://stackoverflow.com/questions/3408078/resourcemanager-override-getresourcefilename

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!