Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 访问(待)编译控件中的本地化资源_C#_.net_Localization_Controls - Fatal编程技术网

C# 访问(待)编译控件中的本地化资源

C# 访问(待)编译控件中的本地化资源,c#,.net,localization,controls,C#,.net,Localization,Controls,我有一个组件项目与我们的网站控制-现在必须能够本地化。为站点的其余部分设置本地化不是问题(我们将.resx文件放入App\u GlobalResources目录;一切都很好),但我很难找到如何在组件项目中本地访问资源的信息 App\u Local[/Global]Resources文件夹不需要工作-我不能像从主项目中那样“添加ASP.NET文件夹” 当我自己生成它并将.resx文件放入其中时,我不知道如何像在站点中那样访问它们 一些缩写控制代码,完全包含在组件项目中的ThisWidget.c

我有一个组件项目与我们的网站控制-现在必须能够本地化。为站点的其余部分设置本地化不是问题(我们将
.resx
文件放入
App\u GlobalResources
目录;一切都很好),但我很难找到如何在组件项目中本地访问资源的信息

  • App\u Local[/Global]Resources
    文件夹不需要工作-我不能像从主项目中那样“添加ASP.NET文件夹”
  • 当我自己生成它并将.resx文件放入其中时,我不知道如何像在站点中那样访问它们
一些缩写控制代码,完全包含在组件项目中的
ThisWidget.cs
中:

namespace site.shop {
  [ToolboxData("<{0}:ThisWidget runat=server></{0}:ThisWidget>")]
  public class ThisWidget : WebControl {
    protected override void CreateChildControls() {
      if (ChildControlsCreated) { return; }
      this.Controls.Clear();
      Label head = new Label();
      head.CssClass = "header";

      // fails: ThisWidget does not exist in namespace
      head.Text = System.Resources.ThisWidget.Label_head;
      // fails: can't find GetLocalResourceObject
      head.Text = new System.Web.UI.TemplateControl.GetLocalResourceObject("Label_head");
      // fails: can't find linked or embedded resources
      System.Resources.ResourceManager rm = new ResourceManager();
      head.Text = Convert.ToString(rm.GetObject("Label_head"));

      this.Controls.Add(head);
    }
  }
}
namespace site.shop{
[ToolboxData(“”)
公共类ThisWidget:WebControl{
受保护的覆盖无效CreateChildControls(){
if(ChildControlsCreated){return;}
this.Controls.Clear();
标签头=新标签();
head.CssClass=“header”;
//失败:此小部件在命名空间中不存在
head.Text=System.Resources.ThisWidget.Label\u head;
//失败:找不到GetLocalResourceObject
head.Text=new System.Web.UI.TemplateControl.GetLocalResourceObject(“Label_head”);
//失败:找不到链接或嵌入的资源
System.Resources.ResourceManager rm=new ResourceManager();
head.Text=Convert.ToString(rm.GetObject(“Label_head”);
this.Controls.Add(head);
}
}
}
以及使用/out
new
System.Web.UI.TemplateControl
等的几个变体

我不想把它编译成附属程序集,然后把它拉回来(这似乎是另一个选项),因为组件项目(a)有很多相关控件,(b)已经是附属依赖项了,对吗?我希望我能把
.resx
文件放进去,编译
.DLL
,然后项目的其余部分就可以工作了

[编辑] 我觉得我离答案越来越近了,但我还没完全找到答案

有什么想法吗?我错过了什么


谢谢

哦,我快到了-我打开了
ThisWidget.Designer.cs
并找到了正确的参数来调用
ResourceManager()

ResourceManager rm = new ResourceManager("Components.App_LocalResources.ThisWidget", typeof(ThisWidget).Assembly);
head.Text = Convert.ToString(rm.GetObject("Label_head"));
看起来很有魅力。我还意识到,由于它忽略了
App\u LocalResources
的特殊性,我可以将它放在任何地方,因此我创建了一个
/Resources/Resx/
目录,并将每个组件控件的
.Resx
文件放在其中。要更新呼叫,请执行以下操作:

ResourceManager rm = new ResourceManager("Components.Resources.Resx.ThisWidget", typeof(ThisWidget).Assembly);