2011-12-21 111 views
0

我想在WPF应用程序中有一个类,该类可以从resx生成的类中提取字符串,而无需知道实际的resx。然而比),以instantitiate ResourceManager中并且使用的GetString(所需的PARAMS如何实例化资源管理器

测试所显示的项目结构其他失败:

enter image description here

[Test] 
public void CanGetString() { 
    var expected = MainWindow.MenuItem_Header_English; // value is "English" 
      var baseName = MainWindow.ResourceManager.BaseName; 
      var asm = typeof (MainWindow).Assembly; 
      var rm = new ResourceManager(baseName, asm); 
    var actual = rm.GetString("MenuItem_Header_English"); // returns null 
    Assert.That(expected, Is.EqualTo(actual)); 
} 

有人能证实这一点应该是可能的,并告诉我做错了什么?有没有更好的方法来读取字符串值嵌入式资源?

干杯,
Berryl

+0

你不能比较字符串文字的类型,所以你想要的是不可能的..现在为了你的测试,你将不得不弄清楚如何得到标题类型并检查名字好运 – MethodMan 2011-12-21 18:15:51

回答

0

将这项工作对你

var rm = MainWindow.ResourceManager.GetString("MenuItem_Header_English") 
    var expected = MainWindow.MenuItem_Header_English; 

//不知道你是如何比较字符串值什么看起来像一个类型..

相关问题