MethodBase.GetParameters 方法
当在派生类中重写时,获取指定的方法或构造函数的参数。
**命名空间:**System.Reflection
**程序集:**mscorlib(在 mscorlib.dll 中)
语法
声明
Public MustOverride Function GetParameters As ParameterInfo()
用法
Dim instance As MethodBase
Dim returnValue As ParameterInfo()
returnValue = instance.GetParameters
public abstract ParameterInfo[] GetParameters ()
public:
virtual array<ParameterInfo^>^ GetParameters () abstract
public abstract ParameterInfo[] GetParameters ()
public abstract function GetParameters () : ParameterInfo[]
返回值
ParameterInfo 类型的数组,包含与此 MethodBase 实例所反射的方法(或构造函数)的签名匹配的信息。
示例
' 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
// 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);
}
}
}
// 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;
void Fire( int i )
{
ev += gcnew MyDelegate( this, &MainClass::Fire );
}
};
int main()
{
Type^ deleg = MainClass::typeid->GetEvent( "ev" )->EventHandlerType;
MethodInfo^ invoke = deleg->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 );
}
}
.NET Framework 安全性
- ReflectionPermission 当通过类似 Type.InvokeMember 的机制以后期绑定的形式进行调用时。关联的枚举:ReflectionPermissionFlag.MemberAccess。
平台
Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition
.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求。
版本信息
.NET Framework
受以下版本支持:2.0、1.1、1.0
.NET Compact Framework
受以下版本支持:2.0、1.0
请参见
参考
MethodBase 类
MethodBase 成员
System.Reflection 命名空间
ParameterInfo