ParameterInfo.IsOut Tulajdonság
Definíció
Fontos
Egyes információk olyan, kiadás előtti termékekre vonatkoznak, amelyek a kiadásig még jelentősen módosulhatnak. A Microsoft nem vállal kifejezett vagy törvényi garanciát az itt megjelenő információért.
Beolvas egy értéket, amely jelzi, hogy ez egy kimeneti paraméter.
public:
property bool IsOut { bool get(); };
public bool IsOut { get; }
member this.IsOut : bool
Public ReadOnly Property IsOut As Boolean
Tulajdonság értéke
trueha a paraméter kimeneti paraméter; egyéb esetben. false
Példák
Az alábbi példa bemutatja, hogyan tesztelheti a metódus paramétereit a ParameterAttributes.In, ParameterAttributes.Outés ParameterAttributes.Optional attribútumok esetében.
A példa egy metódust DefineMethod tartalmaz, amely a következőket teszi:
Létrehoz egy típust tartalmazó dinamikus szerelvényt
MyType.Metódust ad
MyMethodhozzá a fájlhozMyType.MyMethodhárom paraméterből áll. Az első paraméter a következővel ParameterAttributes.Invan definiálva, a második a következővel ParameterAttributes.Out, a harmadik pedig a következővel ParameterAttributes.Optional: .A típus befejezésére irányuló hívások TypeBuilder.CreateType .
A végrehajtás DefineMethodután a példa megkeresi a jelenleg betöltött szerelvényeket, amíg meg nem találja a dinamikus szerelvényt. Betölti MyType a szerelvényt, lekéri MethodInfo a MyMethod metódus objektumát, és megvizsgálja a paramétereket. A példa a IsIn, IsOutés IsOptional a tulajdonságok használatával jeleníti meg a paraméterekkel kapcsolatos információkat.
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
Megjegyzések
Ez a módszer egy választható metaadat-jelzőtől függ. Ezt a jelzőt a fordítók beszúrhatják, de a fordítóknak nincs erre kötelezve.
Ez a metódus az Out enumerátor zászlaját ParameterAttributes használja.
A ParameterInfo tömb lekéréséhez először kérje le a metódust vagy a konstruktort, majd hívja meg MethodBase.GetParameters.