[英]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.InvokeMethod
和BindingFlags.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.