从RESX文件中读取值? [英] Read values from resx files?

查看:988
本文介绍了从RESX文件中读取值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何阅读从C#中的MyResource.resx文件中的字符串。
我不是从asp.net页面调用这个,而我从我的经营业务逻辑调用。

How to read strings from the MyResource.resx file from c#. I am not calling this from the asp.net page, rather i am calling from my bussiness logic.

装配装配=
  this.GetType()汇编。
  
ResourceManager的ResourceManager的新=
  ResourceManager的(MessagesResource
  部件);
  
resourceManager.GetString(SCHEME_UNQ);

Assembly assembly = this.GetType().Assembly;
ResourceManager resourceManager = new ResourceManager("MessagesResource", assembly);
resourceManager.GetString("SCHEME_UNQ");

在这里我得到异常,

找不到任何资源
  适合于指定文化
  或中性文化。确保
  MessagesResource.resources是
  正确嵌入或链接到
  集结号App_Web_eerdggo8在编译
  时间,或者说,所有的卫星
  需要集都可加载和
  完全签名。

Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "MessagesResource.resources" was correctly embedded or linked into assembly "App_Web_eerdggo8" at compile time, or that all the satellite assemblies required are loadable and fully signed.

我怎么能解决这个问题????

How can i fix this issue????

推荐答案

一旦你添加一个RESX文件到您的项目,Visual Studio将自动生成一个设计类,它可以读取值(在RESX文件的属性你必须有自定义工具:ResXFile codeGenerator )。例如,如果您添加 Messages.resx 到你的项目,你可以直接从它读值:

Once you add a resx file to your project, Visual Studio will automatically generate a designer class which allows you to read value (In the properties of the resx file you must have Custom Tool: ResXFileCodeGenerator). For example if you add Messages.resx to your project you could directly read values from it:

string value = Messages.SomeResourceKey;

这篇关于从RESX文件中读取值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆