PropertyInfo : is the property an indexer?

*爱你&永不变心* 提交于 2019-11-29 09:02:35

Call PropertyInfo.GetIndexParameters - if the returned array is empty, it's not an indexer.

Another option is to use:

myType.GetProperties().Except(myType.GetDefaultMembers().OfType<PropertyInfo>());

GetDefaultMembers will return all the compiler generated indexers in C#. This has the advantage of not needing to reflect on each individual property in order to find out which ones are indexers.

This might not be a general solution for all allowed .NET framework languages, but I am currently not aware of any counter-examples.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!