System.Reflection.PropertyInfo and System.Reflection.ParameterInfo don't seem to expose any way to get the values used at runtime to access indexed property values. If correct, this means that one must know the index values (i.e. keys) in advance - unlike a dictionary, there is no .Keys or similar construct to give access to those index values.
My goal is to be able to take an indexed property accessible via a string key and use its keys and values to construct a new dictionary. Is there any way to do this?
No, there's no way of doing this - because it doesn't make sense to do so.
Like properties, indexers are just methods with some extra metadata. So this:
Is just like this:
If the indexer has a setter, that's just another method with an extra parameter as the value being set.
Look at the indexer above - what would you say the "indexed property values" are? It can work with any
intvalues. That's certainly not a typical indexer, but it's entirely valid from a language perspective.If you're writing an indexer which only accepts some inputs, you can choose to expose that (just as
Dictionary<,>exposes aKeysproperty) but it's up to you to do so.