简体   繁体   English

被称为Type.InvokeMember无效。 如何获得资源价值?

[英]calledType.InvokeMember don't work. How to get value of resource?

I try to get a value of ressource.resx and I can't. 我尝试获取ressource.resx的值,但我做不到。

I do : 我做 :

foreach (string certif in ContactCertifications)
{
    Type calledType = Type.GetType("TestNamespace.Resources");            

    String s = (String)calledType.InvokeMember(certif,BindingFlags.InvokeMethod 

    | BindingFlags.Public |BindingFlags.Static,null,null,null);                                       }

certif = "PRG_CARTV" certif =“ PRG_CARTV”

calledType is : {Name = "Resources" FullName = "TestNamespace.Resources"} and when I'm in line "String s = (String)calledType" I have an error : "Method 'TestNamespace.Resources.PRG_CARTV' not found." namedType是:{Name =“ Resources” FullName =“ TestNamespace.Resources”},当我在“ String s =(String)namedType”行中时,出现错误:“找不到方法'TestNamespace.Resources.PRG_CARTV'。 “

And when I have String s = TestNamespace.Resources.PRG_CARTV; 当我有String s = TestNamespace.Resources.PRG_CARTV; it's work, so I don't understend.. 它在工作,所以我不懂。

When I do simply : 当我简单地做:

var myManager = new ResourceManager(typeof(Resources));
var myString = myManager.GetString("PRG_CARTV");

it's doesn't work, I have a error : "Can not find appropriate resources for the specified culture or neutral culture. Make sure \\ "TestNamespace.Ressources.resources \\" has been correctly embedded or linked in the assembly ..." 它不起作用,出现一个错误:“找不到用于指定区域性或中性区域性的适当资源。请确保\\“ TestNamespace.Ressources.resources \\”已正确嵌入或链接到程序集中...”

You have 2 problems here: 您在这里有2个问题:

1) Getting the value of a resource via reflection, I tried this one and worked: 1)通过反射获得资源的价值,我尝试了这一方法并工作:

String s = (String) calledType.InvokeMember(certif, BindingFlags.GetProperty | BindingFlags.NonPublic | BindingFlags.Static, null, null, null);

Note the binding flags that changed: BindingFlags.GetProperty instead of BindingFlags.InvokeMethod and BindingFlags.NonPublic instead of BindingFlags.Public 请注意已更改的绑定标志: BindingFlags.GetProperty而不是BindingFlags.InvokeMethodBindingFlags.NonPublic而不是BindingFlags.Public

2) Issue with the ResourceManager. 2)问题与ResourceManager有关。 I myself would try to recreate the Resources.resx again. 我本人将尝试再次重新创建Resources.resx。 If you want to investigate further check similar problems here in StackOverflow, for example: Could not find any resources appropriate for the specified culture or the neutral culture 如果要进一步调查,请在此处检查StackOverflow中的类似问题,例如: 找不到适合于指定区域性或中性区域性的任何资源

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C#invokeMember单击将不起作用 - c# invokeMember click won't work InvokeMember获得特定属性值的可能值 - Possible values for InvokeMember to get specific property value DeleteOnSubmit()和SubmitChanges()不起作用。 没有异常或错误。 InsertOnSubmit()工作正常 - DeleteOnSubmit() and SubmitChanges() don't work. No exception or error. InsertOnSubmit() works fine WPF Grid horizo​​ntalalignment不起作用。 尺寸不会改变 - WPF Grid horizontalalignment doesn't work. Sizes don't changes InvokeMember(“ click”)在线程内的webBrowser控件中不起作用 - InvokeMember(“click”) doesn't work in webBrowser control inside a thread 使用谓词绑定在命令上的搜索栏不起作用。 Xamarin.Forms - Search bar bound on command with predicate don't work. Xamarin.Forms NuGet安装软件包不起作用。 如何获取更多详细信息以帮助调试为什么失败? - NuGet install-package doesn't work. How can I get more verbose information to help debug why this is failing? 绑定值无法正常工作 - Binding value don't work correctly 从Angular 2到ASP.net Core的POST请求不起作用。 服务器端的空值 - POST request from Angular 2 to ASP.net Core doesn't work. Null value on server side 解析源文件并尝试获取其方法不起作用。 为什么它不起作用? - Parsing source file and trying to get its methods doesn't work. Why is it not working?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM