ParameterInfo.IsOut プロパティ
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
これが出力パラメーターかどうかを示す値を取得します。
public:
property bool IsOut { bool get(); };
public bool IsOut { get; }
member this.IsOut : bool
Public ReadOnly Property IsOut As Boolean
プロパティ値
true パラメーターが出力パラメーターの場合。それ以外の場合は false。
例
次の例は、 ParameterAttributes.In、 ParameterAttributes.Out、および ParameterAttributes.Optional 属性のメソッド パラメーターをテストする方法を示しています。
この例には、次の DefineMethod メソッドが含まれています。
MyType型を含む動的アセンブリを作成します。MyMethodメソッドをMyTypeに追加します。MyMethodには 3 つのパラメーターがあります。 最初のパラメーターは、 ParameterAttributes.In、2 番目のパラメーターは ParameterAttributes.Out、3 番目のパラメーターは ParameterAttributes.Optional で定義されます。TypeBuilder.CreateTypeを呼び出して型を完了します。
DefineMethodを実行した後、動的アセンブリが見つかるまで、現在読み込まれているアセンブリを検索します。 アセンブリからMyTypeを読み込み、MethodInfo メソッドのMyMethod オブジェクトを取得し、パラメーターを調べます。 この例では、 IsIn、 IsOut、および IsOptional プロパティを使用して、パラメーターに関する情報を表示します。
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
注釈
このメソッドは、省略可能なメタデータ フラグに依存します。 このフラグはコンパイラによって挿入できますが、コンパイラでは挿入する必要はありません。
このメソッドは、Out列挙子のParameterAttributes フラグを使用します。
ParameterInfo配列を取得するには、まずメソッドまたはコンストラクターを取得してから、MethodBase.GetParametersを呼び出します。