MethodBase.GetParameters 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, gets the parameters of this method or constructor.

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


Public MustOverride Function GetParameters As ParameterInfo()
public abstract ParameterInfo[] GetParameters()

Return Value

Type: array<System.Reflection..::.ParameterInfo>[]()[]
An array that contains the parameters of this method or constructor.


Exception Condition

This member is invoked late-bound through mechanisms such as Type..::.InvokeMember.


The following example uses the GetParameters method to retrieve the parameters of the Invoke method of a delegate.

The example defines a delegate named MyDelegate and an event named ev of type MyDelegate. The code in the Main method discovers the event signature by getting the delegate type of the event, getting the Invoke method of the delegate type, and then retrieving and displaying the parameters.

Imports System.Reflection

Public Delegate Sub MyDelegate(ByVal i As Integer, ByRef s As String)

Public Class Example
    Public Event MyEvent As MyDelegate

    Public Shared Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)

        Dim delegateType As Type = GetType(Example).GetEvent("MyEvent").EventHandlerType

        ' The Invoke method of a delegate type always has the same signature
        ' as the delegate.
        Dim invoke As MethodInfo = delegateType.GetMethod("Invoke")

        For Each p As ParameterInfo In invoke.GetParameters()
            outputBlock.Text &= p.ParameterType.ToString() & vbLf
        Next p
    End Sub 
End Class 

' This example produces the following output:
using System;
using System.Reflection;

public delegate void MyDelegate(int i, ref string s);

public class Example
    public event MyDelegate MyEvent;

    public static void Demo(System.Windows.Controls.TextBlock outputBlock)
        Type delegateType = typeof(Example).GetEvent("MyEvent").EventHandlerType;

        // The Invoke method of a delegate type always has the same signature
        // as the delegate.
        MethodInfo invoke = delegateType.GetMethod("Invoke");

        foreach( ParameterInfo p in invoke.GetParameters() )
            outputBlock.Text += p.ParameterType.ToString() + "\n";

/* This example produces the following output:


Version Information

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0


Windows Phone

See Also


MethodBase Class

System.Reflection Namespace