【问题标题】:How to read resourcefile from dll c#如何从 dll c# 中读取资源文件
【发布时间】:2017-01-30 09:01:32
【问题描述】:

我想使用资源文件来获取一些文本。这些资源文件将在 dll 中。这与本地化无关,以防万一你问。 我希望能够根据配置设置选择要使用的 rexfile。

示例 我的公司.RexFiles.dll

  1. RexFileA
  2. RexFileB
  3. RexFileC

我的问题 鉴于在配置文件中我有一个设置来决定使用哪个 rexfile,例如 CurrentRexfile="RexFileB"

如何根据 configSettings 默认使用正确的 rexFile。

任何建议

【问题讨论】:

  • 也许是一些高级反思?

标签: c# resource-files


【解决方案1】:

您可以使用 ResourceManager 类来检索资源:

System.Reflection.Assembly myAssembly = this.GetType().Assembly;

string rexFile = ConfigurationManager.AppSettings["CuurentRexfile"];
System.Reflection.Assembly otherAssembly = System.Reflection.Assembly.Load(rexFile);

System.Resources.ResourceManager resManager = new System.Resources.ResourceManager("ResourceNamespace.myResources", otherAssembly);

string test = resManager.GetString("resourceString");

更多阅读here

【讨论】:

  • 感谢您的回复。使用属性可以工作吗?我的意思是在属性中调用“resManager.GetString("resourceString")。我希望它可以被包装起来像资源一样被调用。MyName- resources.MySurname 等...
  • 对不起,我现在很困惑,不知道你指的是什么属性。
猜你喜欢
  • 1970-01-01
  • 2013-03-21
  • 2016-06-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-09-29
相关资源
最近更新 更多