出于某种原因,这段代码:
MethodInfo iDataReaderIndexerProperty = typeof(IDataReader).GetProperties()
.Single(property => property.GetIndexParameters().Length > 0)
.GetGetMethod();
失败。如果我将 IDataReader
替换为 IMyInterface
定义为:
interface IMyInterface
{
String this[Int32 index] { get; }
}
它工作正常。 IDataReader
如何定义它的索引器?
最佳答案
该索引器是在 IDataRecord
上定义的,而不是 IDataReader
;所以你需要从typeof(IDataRecord)
查询,和使用Servy的观察有多个重载(string
vs int
).
关于c# - IDataReader 如何定义它的索引器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17155223/