我对反射、动态调用对象和读取集合值有问题。
在引用的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
)(在对象浏览器中不可见/不存在)