DLeh
DLeh

Reputation: 24405

GetIndexParameters() empty on Dictionary property

I'm using reflection to get some info about a class I'm exporting to excel. It loops through the properties to get their values.

I want it to also be able to handle indexed types like Lists and Dictionarys. However, the GetIndexParameters() method on the property is returning none. Am I using this wrong?

Here you can see that prop.Property (which is a PropertyInfo) is showing the value as a Dictionary<int, decimal>, but the indexParams has 0 length.

Loop logic (slightly modified for SO, partially pseudocode)

foreach (var prop in ExportingPropertiesInOrder)
{
    //detect if it needs to have indexing applied.
    var indexParams = prop.Property.GetIndexParameters();
    var isIndexed = indexParams.Any();
    if (!isIndexed)
    {
        //get value for property for export
    }else{
        //loop through indeces, get each value
    }

Upvotes: 0

Views: 288

Answers (1)

ASh
ASh

Reputation: 35730

the property which is shown on screenshot is Dictionary<int, decimal> TierValues

it is NOT an indexer, so GetIndexParameters() method on the property is returning empty array

Dictionary<int, decimal> type itself HAS indexed property Item

Upvotes: 1

Related Questions