MethodBase.GetParameters Metodo
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Quando viene sottoposto a override in una classe derivata, ottiene i parametri del metodo o del costruttore specificato.
public:
abstract cli::array <System::Reflection::ParameterInfo ^> ^ GetParameters();
public abstract System.Reflection.ParameterInfo[] GetParameters ();
abstract member GetParameters : unit -> System.Reflection.ParameterInfo[]
Public MustOverride Function GetParameters () As ParameterInfo()
Matrice di tipo ParameterInfo
contenente le informazioni corrispondenti alla firma del metodo (o del costruttore) ottenuto mediante reflection da questa istanza di MethodBase
.
Nell'esempio Invoke
seguente viene usato il GetParameters metodo per recuperare i parametri del metodo di un delegato.
L'esempio definisce un delegato denominato e un evento denominato MyDelegate
ev
di tipo MyDelegate
. Il codice nel Main
metodo individua la firma dell'evento recuperando il tipo delegato dell'evento, recuperando il Invoke
metodo del tipo delegato e quindi recuperando e visualizzando i parametri.
// 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 );
}
}
// The example displays the following output:
// System.Int32
// 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);
}
}
}
// The example displays the following output:
// System.Int32
Imports System.Reflection
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()
For Each p As ParameterInfo In pars
Console.WriteLine(p.ParameterType)
Next
End Sub
End Class
' The example displays the following output:
' System.Int32
Prodotto | Versioni |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1 |
UWP | 10.0 |
Feedback su .NET
.NET è un progetto open source. Seleziona un collegamento per fornire feedback: