c# - 如何从C#中的特定资源文件中获取字符串资源

标签 c# .net asp.net-mvc localization

在我们的项目中的某些情况下,我们必须忽略应用程序的当前文化 并获取英文资源。

基本上,我们对所有语言都这样做

<label>@ModelEntities.Properties.Resource.Gender</label>

怎么可能只有英文?

我假设我们已经以某种方式创建了一些对 Resource.resx 的引用?

我用过

 ResourceManager rm = new ResourceManager("Resource.Strings",
                     Assembly.GetAssembly(typeof(ModelEntities.Properties.Resource))); 
  var s = rm.GetString("Age");

但是好像不行。

谢谢!

最佳答案

我找到了可行的解决方案。

首先我们的资源文件都是这样结束的

Resource.resx

不像Resources.resx

第二,我们在单独的程序集中有资源:ModelEntities

下面是工作代码

var resourceManager = new ResourceManager(typeof(ModelEntities.Properties.Resource)); 
var genderString = resourceManager.GetString("Gender", ci);

关于c# - 如何从C#中的特定资源文件中获取字符串资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26591232/

相关文章:

C#数组题(拆分)

c# - 如何在 web api get 中返回 IEnumerable DbSet?

asp.net-mvc - 如何防止ASP.NET MVC中的JSON序列化?

asp.net-mvc - ASP.NET MVC : Retrieving form fields with the same name

带有 MVVM 的 C# 泛型,将 T 从 <T> 中拉出

c# - 统一将相机附加到可编写脚本的对象

c# - Unity防止点击1s

.net - 你如何指定一个方法只能被单元测试调用?

.net - 如何更改 Winforms 中的 TrackBar 刻度颜色?

javascript - 表格内的可点击按钮