Freigeben über


ParameterInfo.ParameterType-Eigenschaft

Ruft den Type dieses Parameters ab.

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

Syntax

'Declaration
Public Overridable ReadOnly Property ParameterType As Type
'Usage
Dim instance As ParameterInfo
Dim value As Type

value = instance.ParameterType
public virtual Type ParameterType { get; }
public:
virtual property Type^ ParameterType {
    Type^ get ();
}
/** @property */
public Type get_ParameterType ()
public function get ParameterType () : Type

Eigenschaftenwert

Das Type-Objekt, das den Type dieses Parameters darstellt.

Hinweise

Diese Methode hängt von einem optionalen Metadatenflag ab und ist u. U. nicht in allen Compilern verfügbar.

Rufen Sie zum Abrufen des ParameterInfo-Arrays zunächst die Methode oder den Konstruktor ab, und rufen Sie dann MethodBase.GetParameters auf.

Beispiel

Imports System
Imports System.Reflection
Imports Microsoft.VisualBasic

Class parminfo
    
    Public Shared Sub mymethod(int1m As Integer, ByRef str2m As String, _
    ByRef str3m As String)
        str2m = "in mymethod"
    End Sub
       
    Public Shared Function Main() As Integer
        Console.WriteLine(ControlChars.CrLf + "Reflection.Parameterinfo")
        
        'Get the ParameterInfo parameter of a function.
        'Get the type.
        Dim Mytype As Type = GetType(parminfo)
        
        'Get and display the method.
        Dim Mymethodbase As MethodBase = Mytype.GetMethod("mymethod")
        Console.Write(ControlChars.CrLf _
           + "Mymethodbase = " + Mymethodbase.ToString())
        
        'Get the ParameterInfo array.
        Dim Myarray As ParameterInfo() = Mymethodbase.GetParameters()
        
        'Get and display the ParameterInfo of each parameter.
        Dim Myparam As ParameterInfo
        For Each Myparam In  Myarray
            Console.Write(ControlChars.CrLf _
               + "For parameter # " + Myparam.Position.ToString() _
               + ", the ParameterType is - " + Myparam.ParameterType.ToString())
        Next Myparam
        Return 0
    End Function
End Class

' This code produces the following output:
' 
' Reflection.Parameterinfo

' Mymethodbase = Void mymethod(Int32, System.String ByRef, System.String ByRef)
' For parameter # 0, the ParameterType is - System.Int32
' For parameter # 1, the ParameterType is - System.String&
' For parameter # 2, the ParameterType is - System.String& 
 using System;
 using System.Reflection;

 class parminfo
 {
    public static void mymethod (
       int int1m, out string str2m, ref string str3m)
    {
       str2m = "in mymethod";
    }
  
    public static int Main(string[] args)
    {
       Console.WriteLine("\nReflection.Parameterinfo");
       
       //Get the ParameterInfo parameter of a function.
  
       //Get the type.
       Type Mytype = Type.GetType("parminfo");
  
       //Get and display the method.
       MethodBase Mymethodbase = Mytype.GetMethod("mymethod");
       Console.Write("\nMymethodbase = " + Mymethodbase);
  
       //Get the ParameterInfo array.
       ParameterInfo[]Myarray = Mymethodbase.GetParameters();
       
       //Get and display the ParameterInfo of each parameter.
       foreach (ParameterInfo Myparam in Myarray)
       {
          Console.Write ("\nFor parameter # " + Myparam.Position 
             + ", the ParameterType is - " + Myparam.ParameterType);
       }
       return 0;
    }
 }

 /*
 This code produces the following output:
 
Reflection.Parameterinfo

Mymethodbase = Void mymethod(Int32, System.String ByRef, System.String ByRef)
For parameter # 0, the ParameterType is - System.Int32
For parameter # 1, the ParameterType is - System.String&
For parameter # 2, the ParameterType is - System.String&
 */
using namespace System;
using namespace System::Reflection;
using namespace System::Runtime::InteropServices;
public ref class parminfo
{
public:
   static void mymethod( int int1m, [Out]interior_ptr<String^> str2m, interior_ptr<String^> str3m )
   {
       *str2m = "in mymethod";
   }

};

int main()
{
   Console::WriteLine( "\nReflection.Parameterinfo" );
   
   //Get the ParameterInfo parameter of a function.
   //Get the type.
   Type^ Mytype = Type::GetType( "parminfo" );
   
   //Get and display the method.
   MethodBase^ Mymethodbase = Mytype->GetMethod( "mymethod" );
   Console::Write( "\nMymethodbase = {0}", Mymethodbase );
   
   //Get the ParameterInfo array.
   array<ParameterInfo^>^Myarray = Mymethodbase->GetParameters();
   
   //Get and display the ParameterInfo of each parameter.
   System::Collections::IEnumerator^ enum0 = Myarray->GetEnumerator();
   while ( enum0->MoveNext() )
   {
      ParameterInfo^ Myparam = safe_cast<ParameterInfo^>(enum0->Current);
      Console::Write( "\nFor parameter # {0}, the ParameterType is - {1}", Myparam->Position, Myparam->ParameterType );
   }

   return 0;
}

/*
This code produces the following output:

Reflection.Parameterinfo

Mymethodbase = Void mymethod(Int32, System.String ByRef, System.String ByRef)
For parameter # 0, the ParameterType is - System.Int32
For parameter # 1, the ParameterType is - System.String&
For parameter # 2, the ParameterType is - System.String&
*/
import System.*;
import System.Reflection.*;

class Parminfo
{   
    public static void Mymethod(int int1m,
        /** @ref
         */ String str2m,
        /** @ref
         */ String str3m)
    {
        str2m = "in mymethod";
    } //Mymethod

    public static void main(String[] args)
    {
        Console.WriteLine("\nReflection.Parameterinfo");

        //Get the ParameterInfo parameter of a function.
        //Get the type.
        Type myType = Type.GetType("Parminfo");

        //Get and display the method.
        MethodBase myMethodBase = myType.GetMethod("Mymethod");
        Console.Write(("\nMymethodbase = " + myMethodBase));

        //Get the ParameterInfo array.
        ParameterInfo myArray[] = myMethodBase.GetParameters();
        //Get and display the ParameterInfo of each parameter.
        for(int iCtr=0; iCtr < myArray.length; iCtr++) {
            ParameterInfo myParam = myArray[iCtr];
            Console.Write(("\nFor parameter # " + myParam.get_Position() 
                + ", the ParameterType is - " + myParam.get_ParameterType()));
        }
    } //main
} //parminfo

/*
 This code produces the following output:
 
Reflection.Parameterinfo

mymethodbase = Void mymethod(Int32, System.String ByRef, System.String ByRef)
For parameter # 0, the ParameterType is - System.Int32
For parameter # 1, the ParameterType is - System.String&
For parameter # 2, the ParameterType is - System.String&
 */

Plattformen

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

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

.NET Compact Framework

Unterstützt in: 2.0, 1.0

Siehe auch

Referenz

ParameterInfo-Klasse
ParameterInfo-Member
System.Reflection-Namespace