如何从dll c#中读取资源文件
How to read resourcefile from dll c#
我想使用资源文件来获取一些 text.These 资源文件将在 dll.It 中与本地化无关,以防万一你问。
我希望能够根据配置设置选择要使用的 rexfile。
样本
MyCompany.RexFiles.dll
- RexFileA
- RexFileB
- RexFileC
我的问题
鉴于在配置文件中我有一个设置来决定使用哪个 rexfile 例如 CurrentRexfile="RexFileB"
如何根据配置设置默认为正确的 rexFile。
有什么建议
您可以使用 ResourceManager Class 检索资源:
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
我想使用资源文件来获取一些 text.These 资源文件将在 dll.It 中与本地化无关,以防万一你问。 我希望能够根据配置设置选择要使用的 rexfile。
样本 MyCompany.RexFiles.dll
- RexFileA
- RexFileB
- RexFileC
我的问题 鉴于在配置文件中我有一个设置来决定使用哪个 rexfile 例如 CurrentRexfile="RexFileB"
如何根据配置设置默认为正确的 rexFile。
有什么建议
您可以使用 ResourceManager Class 检索资源:
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