I have a type that has index properties which I want to access via reflection. How can I do that? I suppose an index property is retrievable as a normal property but I have no idea how to get to it by the means of standard reflection. Also, if I have multiple index properties with different signatures like in the following code, is it possible to access each of them?
public class IndexType
{
// Assume some sensible implementation of the getters/setters
public object this[int index] { get; set; }
public object this[string key] { get; set; }
public object this[int index, string key] { get; set; }
}
You should be able to differentiate an index property by the fact that it requires index parameters. This linq query should do that by checking the
GetIndexParametersmethod.Differentiating which is which can be done by inspecting the numbers and type of parameters.
After providing a sensible implementation of your index properties, this code:
Yields: