ParameterInfo.IsOut Proprietà
Definizione
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.
Ottiene un valore che indica se si tratta di un parametro di output.
public:
property bool IsOut { bool get(); };
public bool IsOut { get; }
member this.IsOut : bool
Public ReadOnly Property IsOut As Boolean
Valore della proprietà
true se il parametro è un parametro di output; in caso contrario, false.
Esempio
Nell'esempio seguente viene illustrato come testare i parametri del metodo per gli ParameterAttributes.Inattributi , ParameterAttributes.Oute ParameterAttributes.Optional .
L'esempio contiene un DefineMethod metodo che esegue le operazioni seguenti:
Crea un assembly dinamico contenente un
MyTypetipo.Aggiunge un
MyMethodmetodo aMyType.MyMethodha tre parametri. Il primo parametro viene definito con , il secondo con ParameterAttributes.InParameterAttributes.Oute il terzo con ParameterAttributes.Optional.Chiamate TypeBuilder.CreateType per completare il tipo.
Dopo l'esecuzione DefineMethod, nell'esempio vengono cercati gli assembly attualmente caricati finché non trova l'assembly dinamico.
MyType Carica dall'assembly, ottiene un MethodInfo oggetto per il MyMethod metodo ed esamina i parametri. Nell'esempio vengono usate le IsInproprietà , IsOute IsOptional per visualizzare informazioni sui parametri.
using System;
using System.Reflection;
class parminfo
{
public static void mymethod (
int int1m, out string str2m, ref string str3m)
{
str2m = "in mymethod";
}
public static int Main(string[] args)
{
Console.WriteLine("\nReflection.Parameterinfo");
//Get the ParameterInfo parameter of a function.
//Get the type.
Type Mytype = Type.GetType("parminfo");
//Get and display the method.
MethodBase Mymethodbase = Mytype.GetMethod("mymethod");
Console.Write("\nMymethodbase = " + Mymethodbase);
//Get the ParameterInfo array.
ParameterInfo[] Myarray = Mymethodbase.GetParameters();
//Get and display the IsOut of each parameter.
foreach (ParameterInfo Myparam in Myarray)
{
Console.Write ("\nFor parameter # " + Myparam.Position
+ ", the IsOut is - " + Myparam.IsOut );
}
return 0;
}
}
/*
This code produces the following output:
Reflection.ParameterInfo
Mymethodbase = Void mymethod (int, System.String ByRef, System.String ByRef)
For parameter # 0, the IsOut is - False
For parameter # 1, the IsOut is - True
For parameter # 2, the IsOut is - False
*/
Imports System.Reflection
Class parminfo
Public Shared Sub mymethod(int1m As Integer, ByRef str2m As String, _
ByRef str3m As String)
str2m = "in mymethod"
End Sub
Public Shared Function Main() As Integer
Console.WriteLine(ControlChars.CrLf + "Reflection.Parameterinfo")
'Get the ParameterInfo parameter of a function.
'Get the type.
Dim Mytype As Type = Type.GetType("parminfo")
'Get and display the method.
Dim Mymethodbase As MethodBase = Mytype.GetMethod("mymethod")
Console.Write(ControlChars.CrLf + "Mymethodbase = " _
+ Mymethodbase.ToString())
'Get the ParameterInfo array.
Dim Myarray As ParameterInfo() = Mymethodbase.GetParameters()
'Get and display the IsOut of each parameter.
Dim Myparam As ParameterInfo
For Each Myparam In Myarray
Console.Write(ControlChars.CrLf _
+ "For parameter # " + Myparam.Position.ToString() _
+ ", the IsOut is - " + Myparam.IsOut.ToString())
Next Myparam
Return 0
End Function
End Class
' This code produces the following output:
'
' Reflection.ParameterInfo
'
' Mymethodbase = Void mymethod (Int32, System.String ByRef, System.String ByRef)
' For parameter # 0, the IsOut is - False
' For parameter # 1, the IsOut is - True
' For parameter # 2, the IsOut is - False
Commenti
Questo metodo dipende da un flag di metadati facoltativo. Questo flag può essere inserito dai compilatori, ma i compilatori non sono obbligati a farlo.
Questo metodo usa il Out flag dell'enumeratore ParameterAttributes .
Per ottenere la matrice, ottenere prima il ParameterInfo metodo o il costruttore e quindi chiamare MethodBase.GetParameters.