如何覆盖Resources.Designer.cs中的默认System.Resources.ResourceManager? - c#

我想从System.Resources.ResourceManager文件覆盖Resources.Designer.cs以实现自定义ResourceManager.GetString(...)方法功能。这可能吗?

参考方案

我相信您在这里要问两个独立的问题。您当然可以覆盖ResourceManager.GetString。但是,您不能在自动生成的Resource.Designer.cs代码中使用该替代。要使用它,您必须编写自己的Resource设计器类。

public class MyResourceManager : System.Resources.ResourceManager
{
  // override
  public override GetString(string name)
  {
    // custom code
  }
}

public class MyResourceDesigner
{
  // use your custom class with override
  private static MyResourceManager resourceManager;
  private static CultureInfo resourceCulture;

  public static MyResourceManager ResourceManager
  {
    get
    {
      if (object.ReferenceEquals(resourceManager, null))
      {
        // Resource is just the name of the .resx file
        // be sure to include relevant namespaces
        var temp = new MyResourceManager(
            "MyProject.Resource", 
            typeof(MyResourceDesigner).Assembly);
        resourceManager = temp;
      }

      return resourceManager;
    }
  }

  public static CultureInfo Culture
  {
    get
    {
      return resourceCulture;
    }

    set
    {
      resourceCulture = value;
    }
  }

  // start adding strongly-typed objects
  public static string Foo
  {
    get
    {
      // use your override
      return ResourceManager.GetString("Foo", resourceCulture);
    }
  }
}

Java:从文件系统加载资源 - java

我的项目设定我有以下项目设置:\program.jar \images\logo.png 在我的代码中,我使用相对URL "images/logo.png"引用图像。问题如果我在目录中使用以下命令运行此程序:c:\projects\program_dir\bin\>java -jar program.jar 然后一切正常,Java能…

对于C#资源,为什么未定义Properties? - c#

当我尝试访问我的C#项目资源之一中的字符串属性时,出现以下错误:'ORG.PRJ.MOD.MyClass2' does not contain a definition for 'Properties' 产生错误的代码是:string s = MyClass2.Properties.Resources.TestStri…

从另一个项目/程序集访问resx文件 - c#

我在另一个项目中有一个资源文件,想要访问例如。字符串。我怎样才能做到这一点? 参考方案 这是一个非常古老的问题,但是由于尚未得到回答,而我只是偶然发现了这个问题,因此有一些可能的解决方案:确保将resx的访问修饰符设置为public!链接到resx文件见here然后,您可以直接使用来访问字符串var translatedString = Resources.…

如何使用JavaScript访问嵌入式ASP.NET GlobalResources? - javascript

我正在开发一个遗留的ASP.NET项目,该项目正试图缓慢地进行调整,但是如果没有像巧克力手指屋一样塌陷的情况,我将无法进行重大更改。我试图为此找到解决方案,但由于术语的特定混合(“ javascript”,“ embedded”和/或“ resource”只是为我提供了有关如何嵌入.js文件的信息,而失败了)。 。),这可能是一种怪异的处理方式。该项目将Ap…

从资产中获取材料 - c#

在我的Unity项目中,我尝试用一​​些自制的材料突出显示某些对象。不幸的是,我发现的代码不起作用。下面的脚本被添加到三个不同的GameObjects:Renderer[] rend_ThisObject; Material white, red; void Start() { // I tried the following two code parts:…