GetIndexParameters Method

PropertyInfo.GetIndexParameters Method

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

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

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

public abstract ParameterInfo[] GetIndexParameters()

Return Value

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

ExceptionCondition
MethodAccessException

Application code attempts to access this member late-bound, for example by using the Type.InvokeMember method.

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 number of index parameters of two properties, one that has an index and one that does not.


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 Example
{
   public static int Demo(System.Windows.Controls.TextBlock outputBlock)
   {
      // Get the type and PropertyInfo.
      Type t = Type.GetType("MyProperty");
      PropertyInfo pi = t.GetProperty("Caption");

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

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

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


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2016 Microsoft