Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
MethodBase Class
 GetParameters Method

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
MethodBase..::.GetParameters Method

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

Namespace:  System.Reflection
Assembly:  mscorlib (in mscorlib.dll)
Visual Basic (Declaration)
Public MustOverride Function GetParameters As ParameterInfo()
Visual Basic (Usage)
Dim instance As MethodBase
Dim returnValue As ParameterInfo()

returnValue = instance.GetParameters()
C#
public abstract ParameterInfo[] GetParameters()
Visual C++
public:
virtual array<ParameterInfo^>^ GetParameters() abstract
JScript
public abstract function GetParameters() : ParameterInfo[]

Return Value

Type: array<System.Reflection..::.ParameterInfo>[]()[]
An array of type ParameterInfo containing information that matches the signature of the method (or constructor) reflected by this MethodBase instance.

Implements

_MethodBase..::.GetParameters()()()

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.

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 Delegate Sub MyDelegate(ByVal i As Integer)
Public Class MainClass
    Public Event ev As MyDelegate

    Public Shared Sub Main()
        Dim delegateType As Type = GetType(MainClass).GetEvent("ev").EventHandlerType
        Dim invoke As MethodInfo = delegateType.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 static void Main() 
    {
        Type delegateType = typeof(MainClass).GetEvent("ev").EventHandlerType;
        MethodInfo invoke = delegateType.GetMethod("Invoke");
        ParameterInfo[] pars = invoke.GetParameters();
        foreach (ParameterInfo p in pars) 
        {
            Console.WriteLine(p.ParameterType);
        }
    }
}

Visual C++
// The following example uses instances of classes in
// the System::Reflection namespace to discover an event argument type.
using namespace System;
using namespace System::Reflection;

public delegate void MyDelegate( int i );
public ref class MainClass
{
public:
   event MyDelegate^ ev;
};

int main()
{
   Type^ delegateType = MainClass::typeid->GetEvent( "ev" )->EventHandlerType;
   MethodInfo^ invoke = delegateType->GetMethod( "Invoke" );
   array<ParameterInfo^>^pars = invoke->GetParameters();
   System::Collections::IEnumerator^ myEnum = pars->GetEnumerator();
   while ( myEnum->MoveNext() )
   {
      ParameterInfo^ p = safe_cast<ParameterInfo^>(myEnum->Current);
      Console::WriteLine( p->ParameterType );
   }
}

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0

XNA Framework

Supported in: 3.0, 2.0, 1.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker