[英]How does IDataReader define it's indexer?
出於某種原因,這段代碼:
MethodInfo iDataReaderIndexerProperty = typeof(IDataReader).GetProperties()
.Single(property => property.GetIndexParameters().Length > 0)
.GetGetMethod();
失敗。 如果我更換IDataReader
與IMyInterface
定義為:
interface IMyInterface
{
String this[Int32 index] { get; }
}
它工作正常。 IDataReader
如何定義它的索引器?
有兩個索引器,一個采用int,一個采用字符串。 由於您使用的是Single
並且有兩個匹配項,因此會拋出異常。
你有幾個選擇:
First
得到兩個中的一個 Where
並將兩個索引器作為序列處理 該索引器是在IDataRecord
上定義的,而不是IDataReader
; 所以你需要從typeof(IDataRecord)
查詢, 並使用Servy觀察到有多個重載( string
vs int
)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.