Export (0) Print
Expand All

PropertyInfo.GetIndexParameters Method

When overridden in a derived class, returns an array of all the index parameters for the property.

Namespace:  System.Reflection
Assemblies:   mscorlib (in mscorlib.dll)
  System.Reflection (in System.Reflection.dll)

public abstract ParameterInfo[] GetIndexParameters()

Return Value

Type: System.Reflection.ParameterInfo[]
An array of type ParameterInfo containing the parameters for the indexes. If the property is not indexed, the array has 0 (zero) elements.

Implements

_PropertyInfo.GetIndexParameters()

Extract any required parameter information from the returned array.

To use the GetIndexParameters method, first get the class Type. From the Type, get the PropertyInfo. From the PropertyInfo, use the GetIndexParameters method.

The following example displays the index parameters of the specified property.

using System;
using System.Reflection;

// A class that contains some properties. 
public class MyProperty   
{
    // Define a simple string property. 
    private string caption = "A Default caption";
    public string Caption
    {
        get{return caption;}
        set {if(caption!=value) {caption = value;}
        }
    }

    // A very limited indexer that gets or sets one of four  
    // strings. 
    private string[] strings = {"abc", "def", "ghi", "jkl"};
    public string this[int Index]    
    {
        get
        {
            return strings[Index];
        }
        set
        {
            strings[Index] = value;
        }
    }
}

class Mypropertyinfo
{
    public static int Main()
    {
        // Get the type and PropertyInfo.
        Type t = Type.GetType("MyProperty");
        PropertyInfo pi = t.GetProperty("Caption");

        // Get the public GetIndexParameters method.
        ParameterInfo[] parms = pi.GetIndexParameters();
        Console.WriteLine("\r\n" + t.FullName + "." + pi.Name
            + " has " + parms.GetLength(0) + " parameters.");

        // Display a property that has parameters. The default  
        // name of an indexer is "Item".
        pi = t.GetProperty("Item");
        parms = pi.GetIndexParameters();
        Console.WriteLine(t.FullName + "." + pi.Name + " has " + 
            parms.GetLength(0) + " parameters.");
        foreach( ParameterInfo p in parms )
        {
            Console.WriteLine("   Parameter: " + p.Name);
        }

        return 0;
    }
}
/*
 This example produces the following output:
 MyProperty.Caption has 0 parameters.
 MyProperty.Item has 1 parameters.
    Parameter: Index
 */

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

Supported in: Windows Phone 8.1

Supported in: Windows Phone Silverlight 8.1

Supported in: Windows Phone Silverlight 8

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft