ResourceManager overrides GetResourceFileName

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

I want to override the GetResourceFileName method as follows:

    protected override string GetResourceFileName(CultureInfo culture) {
        string resourceFileName = base.GetResourceFileName(culture);
        return resourceFileName.Replace(".resources", ".resx");
    }

The problem is to initialize the ResourceManager class, I have to use the static method CreateFileBasedResourceManager, which returns a new instance of ResourceManager. (because I need a file resource manager)

How can I override this method? I also tried calling the CreateFileBasedResourceManager private constructor to create an object, but I get this exception (can't I call the 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
1

app.config web.config.

+2

Source: https://habr.com/ru/post/1758391/


All Articles