反射 PropertyInfo.GetValue 来自集合
我在反射、动态调用对象和读取集合值方面遇到问题。
在引用的 COM/Interop 中,它看起来像这样:
ICollection collection = (ICollection)sth.getCollection("parameter");
SomeObject obj = (SomeObject)collection["id='1'"]; //DB WHERE condition
不幸的是,我需要使用反射和动态调用对象来制作它。获取集合相当容易,但读取“obj”则不同。我该怎么写这个?
object oICollection = sthGetCollectionMethod.Invoke(
sthInstance, BindingFlags.Instance | BindingFlags.Public, null,
new object[1] { "parameter" },
System.Globalization.CultureInfo.InvariantCulture);
//and here is the problem:
//how to access object as array/hashtable collection?
object obj = tICollection.GetProperty("???").GetValue(oICollection, ???);
我应该补充一点,在对象浏览器中我看到“this[v object]”,但在 ICollection.GetMethods()
中我正在获取属性 Item (System.Object
) (在对象浏览器中不可见/不存在)
I have problem with reflection, dynamic invoking objects and reading collection values.
In Referenced COM/Interop it would look like this:
ICollection collection = (ICollection)sth.getCollection("parameter");
SomeObject obj = (SomeObject)collection["id='1'"]; //DB WHERE condition
Unfortunetly i need to make it with reflection and dynamic invoking object. Getting collection is rather easy, but reading "obj" is different story. How should i wrote this?
object oICollection = sthGetCollectionMethod.Invoke(
sthInstance, BindingFlags.Instance | BindingFlags.Public, null,
new object[1] { "parameter" },
System.Globalization.CultureInfo.InvariantCulture);
//and here is the problem:
//how to access object as array/hashtable collection?
object obj = tICollection.GetProperty("???").GetValue(oICollection, ???);
I should add that in object browser i see "this[v object]", but in ICollection.GetMethods()
i'm getting property Item (System.Object
) (which is invisible/not there in Object Browser)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您尝试过
get_Item
吗?Have you tried
get_Item
?