This documentation is archived and is not being maintained.

MethodBase.GetParameters Method

When overridden in a derived class, gets the parameters of the specified method or constructor.

[Visual Basic]
Public MustOverride Function GetParameters() As ParameterInfo()
[C#]
public abstract ParameterInfo[] GetParameters();
[C++]
public: virtual ParameterInfo* GetParameters() [] = 0;
[JScript]
public abstract function GetParameters() : ParameterInfo[];

Return Value

An array of type ParameterInfo containing information that matches the signature of the method (or constructor) reflected by this MethodBase instance.

Example

[Visual Basic] 
' The following example uses instances of classes in 
' the System.Reflection namespace to discover an event argument type.
Imports System
Imports System.Reflection
Imports Microsoft.VisualBasic

Public Class MainClass
    Delegate Sub MyDelegate(ByVal i As Integer)
    Public Event ev As MyDelegate
    Public Sub Fire(ByVal i As Integer)
        AddHandler ev, AddressOf Me.Fire
    End Sub 'Fire

    Public Shared Sub Main()
        Dim deleg As Type = GetType(MainClass).GetEvent("ev").EventHandlerType
        Dim invoke As MethodInfo = deleg.GetMethod("Invoke")
        Dim pars As ParameterInfo() = invoke.GetParameters()
        Dim p As ParameterInfo
        For Each p In pars
            Console.WriteLine(p.ParameterType)
        Next p
    End Sub 'Main
End Class 'MainClass

[C#] 
// The following example uses instances of classes in 
// the System.Reflection namespace to discover an event argument type.
using System;
using System.Reflection;

public delegate void MyDelegate(int i);
public class MainClass 
{
    public event MyDelegate ev;
    public void Fire(int i) 
    {
        ev += new MyDelegate(this.Fire);
    }

    public static void Main() 
    {
        Type deleg = typeof(MainClass).GetEvent("ev").EventHandlerType;
        MethodInfo invoke = deleg.GetMethod("Invoke");
        ParameterInfo[] pars = invoke.GetParameters();
        foreach (ParameterInfo p in pars) 
        {
            Console.WriteLine(p.ParameterType);
        }
    }
}

[C++] 
// The following example uses instances of classes in
// the System::Reflection namespace to discover an event argument type.
#using <mscorlib.dll>

using namespace System;
using namespace System::Reflection;

public __delegate void MyDelegate(int  i);

public __gc class MainClass {
public:
   __event MyDelegate*  ev;
public:
   void Fire(int i) {
      ev += new MyDelegate(this, &MainClass::Fire);
   }
};

int main() {
   Type*  deleg = __typeof(MainClass)->GetEvent(S"ev")->EventHandlerType;
   MethodInfo*  invoke = deleg->GetMethod(S"Invoke");
   ParameterInfo*  pars[] = invoke->GetParameters();
   System::Collections::IEnumerator* myEnum = pars->GetEnumerator();
   while (myEnum->MoveNext()) {
      ParameterInfo* p = __try_cast<ParameterInfo*>(myEnum->Current);
      Console::WriteLine(p->ParameterType);
   }
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard

.NET Framework Security: 

See Also

MethodBase Class | MethodBase Members | System.Reflection Namespace | ParameterInfo

Show: