c# - IDataReader 如何定义它的索引器?

标签 c#

出于某种原因,这段代码:

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/

相关文章:

c# - 创建值为 0,1,2,3... 长度的 c# int[]

c# - 为什么 FileStream 和字符串的 MD5 哈希不同 C#

c# - 如何处理null或无效的文本框输入?

c# - 使用 Directory.GetFiles(...) 时拒绝访问路径

c# - 多对多排序

c# - 从 EF 中的集合中删除项目 - 奇怪的问题

c# - 如何在 Exchange EWS 中保存 ItemAttachment 对象中附加的 EmailMessage?

c# - 使用emgu cv将两个子图像添加到一个新图像中

c# - 运算符 '??' 不能应用于类型 'string' 和 'System.DBNull' 的操作数

c# - 如何在 C# 中使用通用接口(interface)从子对象引用父对象?