我在反射、动态调用对象和读取集合值方面遇到问题。
在 Referenced 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()
我得到属性项目(System.Object
)(在对象浏览器中不可见/不存在)