次の方法で共有


PropertyInfo.GetIndexParameters メソッド

派生クラスによってオーバーライドされた場合に、プロパティのすべてのインデックス パラメータの配列を返します。

Public MustOverride Function GetIndexParameters() As ParameterInfo()
[C#]
public abstract ParameterInfo[] GetIndexParameters();
[C++]
public: virtual ParameterInfo* GetIndexParameters() [] = 0;
[JScript]
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 = 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

[C#] 
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
 */

[C++] 
#using <mscorlib.dll>
using namespace System;
using namespace System::Reflection;

// A class that contains some properties.
public __gc class MyProperty   
{
    // Define a simple string property.
private:
    String* caption;
public:
    __property String* get_Caption() {
        return caption;
    }
    __property void set_Caption(String* value) {
        if(caption!=value) {
            caption = value;
        }
    }

    // A very limited indexer that gets or sets one of four 
    // strings.
private:
    String* strings[];
public:
    MyProperty()
    {
        String* temp0 [] = {S"abc", S"def", S"ghi", S"jkl"};
        strings = temp0;
    }

    __property String* get_Item( int Index )
    {
        return strings[Index];
    }
    __property void set_Item( int Index, String* value )
    {
        strings[Index] = value;
    }
};

int main()
{
    // Get the type and PropertyInfo.
    Type* t = Type::GetType(S"MyProperty");
    PropertyInfo* pi = t->GetProperty(S"Caption");

    // Get the public GetIndexParameters method.
    ParameterInfo* parms[] = pi->GetIndexParameters();
    Console::WriteLine(S"\n{0}.{1} has {2} parameters.",
        t->FullName, pi->Name, __box(parms->GetLength(0)));

    // Display a property that has parameters. 
    pi = t->GetProperty(S"Item");
    parms = pi->GetIndexParameters();
    Console::WriteLine(S"{0}.{1} has {2} parameters.",
        t->FullName, pi->Name, __box(parms->GetLength(0)));
    for (int i = 0; i < parms->GetLength(0); i++)
    {
        Console::WriteLine(S"    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
 */

[JScript] 
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
 */

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET, Common Language Infrastructure (CLI) Standard

.NET Framework セキュリティ:

参照

PropertyInfo クラス | PropertyInfo メンバ | System.Reflection 名前空間