Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

MethodBase.GetParameters Method

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

Namespace:  System.Reflection
Assembly:  mscorlib (in mscorlib.dll)
public abstract ParameterInfo[] GetParameters()

Return Value

Type: System.Reflection.ParameterInfo[]
An array that contains the parameters of this method or constructor.
ExceptionCondition
MethodAccessException

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.


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:

System.Int32
System.String&
 */


Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.