我有一个类似自定义索引器的类
public string this[VehicleProperty property]
{
// Code
}
Run Code Online (Sandbox Code Playgroud)
如何在typeof(MyClass).GetProperties()的结果中识别自定义索引器?
CMS*_*CMS 42
您还可以使用PropertyInfo.GetIndexParameters方法查找索引参数,如果它返回的项目超过0,则它是一个索引属性:
foreach (PropertyInfo pi in typeof(MyClass).GetProperties())
{
if (pi.GetIndexParameters().Length > 0)
{
// Indexed property...
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
6918 次 |
最近记录: |