gpt4 book ai didi

c# - 如何从dll c#中读取资源文件

转载 作者:行者123 更新时间:2023-11-30 17:34:48 26 4
gpt4 key购买 nike

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

样本我的公司.RexFiles.dll

  1. Rex文件A
  2. Rex文件B
  3. RexFileC

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

如何根据配置设置默认为正确的 rexFile。

任何建议

最佳答案

您可以使用 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

关于c# - 如何从dll c#中读取资源文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41932037/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com