다음을 통해 공유


PropertyInfo.GetIndexParameters 메서드

파생 클래스에 재정의할 때 속성에 대한 모든 인덱스 매개 변수의 배열을 반환합니다.

네임스페이스: System.Reflection
어셈블리: mscorlib(mscorlib.dll)

구문

‘선언
Public MustOverride Function GetIndexParameters As ParameterInfo()
‘사용 방법
Dim instance As PropertyInfo
Dim returnValue As ParameterInfo()

returnValue = instance.GetIndexParameters
public abstract ParameterInfo[] GetIndexParameters ()
public:
virtual array<ParameterInfo^>^ GetIndexParameters () abstract
public abstract ParameterInfo[] GetIndexParameters ()
public abstract function GetIndexParameters () : ParameterInfo[]

반환 값

인덱스에 대한 매개 변수가 들어 있는 ParameterInfo 형식의 배열입니다.

설명

반환된 배열에서 모든 필요한 매개 변수 정보를 추출합니다.

GetIndexParameters 메서드를 사용하려면 우선 Type 클래스를 가져옵니다. Type에서 PropertyInfo를 가져옵니다. PropertyInfo에서 GetIndexParameters 메서드를 사용합니다.

예제

다음 예제에서는 지정된 속성의 인덱스 매개 변수를 표시합니다.

Imports System
Imports System.Reflection
Imports System.Collections
Imports Microsoft.VisualBasic

' A test class that has some properties.
Public Class MyProperty

    ' Define a simple string property.
    Private myCaption As String = "A Default caption"
    Public Property Caption() As String
        Get
            Return myCaption
        End Get
        Set(ByVal Value As String)
            If myCaption <> value Then
                myCaption = value
            End If
        End Set
    End Property

    ' A very limited indexed default property that gets or
    ' sets one of four string values.
    Private strings() As String = {"abc", "def", "ghi", "jkl"}
    Public Default Property Item(ByVal Index As Integer) As String
        Get
            Return strings(Index)
        End Get
        Set
            strings(Index) = Value
        End Set 
    End Property
End Class

Public Class Example

    Public Shared Function Main() As Integer

        ' Get the type and PropertyInfo.
        Dim t As Type = GetType(MyProperty)
        Dim pi As PropertyInfo = t.GetProperty("Caption")

        ' Get an array containing the parameters (if any).
        Dim params As ParameterInfo() = pi.GetIndexParameters()
        Console.WriteLine(vbCrLf & t.FullName & "." & pi.Name & _
           " has " & params.GetLength(0) & " parameters.")

        ' Display a property that has parameters.
        pi = t.GetProperty("Item")
        params = pi.GetIndexParameters()
        Console.WriteLine(t.FullName & "." & pi.Name & _
           " has " & params.GetLength(0) & " parameters.")
        For Each p As ParameterInfo In params
            Console.WriteLine("   Parameter: " & p.Name)
        Next

        Return 0
    End Function
End Class

' This example produces the following output:
' MyProperty.Caption has 0 parameters.
' MyProperty.Item has 1 parameters.
'    Parameter: Index
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
 */
using namespace System;
using namespace System::Reflection;

// A class that contains some properties.
public ref class MyProperty
{
private:

   // Define a simple string property.
   String^ caption;

public:

   property String^ Caption 
   {
      String^ get()
      {
         return caption;
      }

      void set( String^ value )
      {
         if ( caption != value )
         {
            caption = value;
         }
      }

   }

private:

   // A very limited indexer that gets or sets one of four 
   // strings.
   array<String^>^strings;

public:
   MyProperty()
   {
      array<String^>^temp0 = {"abc","def","ghi","jkl"};
      strings = temp0;
   }


   property String^ Item [int]
   {
      String^ get( int Index )
      {
         return strings[ Index ];
      }

      void set( int Index, String^ value )
      {
         strings[ Index ] = value;
      }

   }

};

int main()
{
   
   // Get the type and PropertyInfo.
   Type^ t = Type::GetType( "MyProperty" );
   PropertyInfo^ pi = t->GetProperty( "Caption" );
   
   // Get the public GetIndexParameters method.
   array<ParameterInfo^>^parms = pi->GetIndexParameters();
   Console::WriteLine( "\n{0}.{1} has {2} parameters.", t->FullName, pi->Name, parms->GetLength( 0 ) );
   
   // Display a property that has parameters. 
   pi = t->GetProperty( "Item" );
   parms = pi->GetIndexParameters();
   Console::WriteLine( "{0}.{1} has {2} parameters.", t->FullName, pi->Name, parms->GetLength( 0 ) );
   for ( int i = 0; i < parms->GetLength( 0 ); i++ )
   {
      Console::WriteLine( "    Parameter: {0}", parms[ i ]->Name );

   }
   return 0;
}

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

// A class that contains some properties.
public class MyProperty
{
    // Define a simple string property.
    private String caption = "A Default caption";

    /** @property 
     */
    public String get_Caption()
    {
        return caption ;
    } //get_Caption
    /** @property 
     */
    public void set_Caption ( String value )
    {
        if (caption != value) {
            caption = value;
        }
    } //set_Caption
   
    // A very limited indexer that gets or sets one of four 
    // strings.
    private String strings[] =  {"abc", "def", "ghi", "jkl"};
    /** @property 
     */
    public String get_Item(int Index)
    {
        return strings[Index] ;
    } //get_Item
    /** @property 
     */
    public void set_Item (int Index,String value)
    {
        strings[Index] = value;
    } //set_Item
} //MyProperty

class MyPropertyInfo
{   
    public static void main(String[] args)
    {
        // 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.get_FullName() + "." + pi.get_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.get_FullName() + "." + pi.get_Name() + " has " 
            + parms.GetLength(0) + " parameters."));

        for(int iCtr=0; iCtr< parms.length; iCtr++) {
            ParameterInfo p = parms[iCtr];
            Console.WriteLine(("   Parameter: " + p.get_Name()));
        }
    } //main
} //MyPropertyInfo
/*
This example produces the following output:
MyProperty.Caption has 0 parameters.
MyProperty.Item has 1 parameters.
Parameter: Index
*/
import System;
import System.Reflection;
 
//Make a property
 public class Myproperty   
 {
    private var caption : String = "A Default caption";
    public function get Caption() : String {
        return caption;
    }
    public function set Caption(value:String) {
        if(caption!=value) caption = value;
    }
 }
 
 class Mypropertyinfo
 {
    public static function Main() : void
       {
       Console.WriteLine ("\nReflection.PropertyInfo");
 
       //Get the type and PropertyInfo
       var MyType : Type = Type.GetType("Myproperty");
       var Mypropertyinfo : PropertyInfo = MyType.GetProperty("Caption");
 
       //Get the public GetIndexParameters Method
       var Myparameterinfoarray : ParameterInfo[] =
          Mypropertyinfo.GetIndexParameters();
       Console.Write ("\n" + MyType.FullName + "." + Mypropertyinfo.Name
          + " has " + Myparameterinfoarray.GetLength(0) + " parameters");
     }
 }
 Mypropertyinfo.Main();
 /*
 Produces the following output
 
 Reflection.PropertyInfo
 Myproperty.Caption has 0 parameters
 */

.NET Framework 보안

플랫폼

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

2.0, 1.1, 1.0에서 지원

.NET Compact Framework

2.0, 1.0에서 지원

참고 항목

참조

PropertyInfo 클래스
PropertyInfo 멤버
System.Reflection 네임스페이스