I have a class with a custom indexer like so
public string this[VehicleProperty property]
{
// Code
}
How can I identify the custom indexer in the results of typeof(MyClass).GetProperties()?
See Question&Answers more detail:osI have a class with a custom indexer like so
public string this[VehicleProperty property]
{
// Code
}
How can I identify the custom indexer in the results of typeof(MyClass).GetProperties()?
See Question&Answers more detail:osYou can also look for index parameters, using the the PropertyInfo.GetIndexParameters method, if it returns more than 0 items, it's an indexed property:
foreach (PropertyInfo pi in typeof(MyClass).GetProperties())
{
if (pi.GetIndexParameters().Length > 0)
{
// Indexed property...
}
}