【发布时间】:2011-08-22 05:23:20
【问题描述】:
我已经创建了一个通用方法,例如
public void BindRecordSet<T>(IEnumerable<T> coll1, string propertyName)
where T : class
在我的“T”类中,我编写了索引器
public object this[string propertyName]
{
get
{
Type t = typeof(SecUserFTSResult);
PropertyInfo pi = t.GetProperty(propertyName);
return pi.GetValue(this, null);
}
set
{
Type t = typeof(SecUserFTSResult);
PropertyInfo pi = t.GetProperty(propertyName);
pi.SetValue(this, value, null);
}
}
现在在我编写代码时使用我的方法
var result = ((T[])(coll1.Result))[0];
string result= secFTSResult[propertyName];
我收到了错误 无法对“T”类型的表达式应用索引
请帮忙 谢谢
【问题讨论】:
-
嗨 BoltClock,BindRecordSet
方法是泛型类型方法,这里 T 是 BindRecordSet ,其中 Student 是一个类
标签: c#