ParameterInfo.IsOut 屬性

定義

取得值,指出這是否為輸出參數。Gets a value indicating whether this is an output parameter.

public:
 property bool IsOut { bool get(); };
public bool IsOut { get; }
member this.IsOut : bool
Public ReadOnly Property IsOut As Boolean

屬性值

Boolean

如果參數是輸出參數,則為 true,否則為 falsetrue if the parameter is an output parameter; otherwise, false.

範例

下列範例顯示如何測試 ParameterAttributes.In 、和屬性的方法參數 ParameterAttributes.Out ParameterAttributes.OptionalThe following example shows how to test method parameters for the ParameterAttributes.In, ParameterAttributes.Out, and ParameterAttributes.Optional attributes.

此範例包含 DefineMethod 可執行下列動作的方法:The example contains a DefineMethod method that does the following:

執行之後 DefineMethod ,此範例會搜尋目前載入的元件,直到找到動態元件為止。After executing DefineMethod, the example searches the assemblies that are currently loaded until it finds the dynamic assembly. 它會 MyType 從元件載入、取得 MethodInfo 方法的物件 MyMethod ,並檢查參數。It loads MyType from the assembly, gets a MethodInfo object for the MyMethod method, and examines the parameters. 此範例會使用 IsInIsOutIsOptional 屬性來顯示有關參數的資訊。The example uses the IsIn, IsOut, and IsOptional properties to display information about the parameters.

using namespace System;
using namespace System::Reflection;
using namespace System::Runtime::InteropServices;
public ref class parminfo
{
public:
   static void mymethod( int int1m, [Out]interior_ptr<String^> str2m, interior_ptr<String^> str3m )
   {
       *str2m = "in mymethod";
   }

};

int main()
{
   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 = {0}", Mymethodbase );
   
   //Get the ParameterInfo array.
   array<ParameterInfo^>^Myarray = Mymethodbase->GetParameters();
   
   //Get and display the IsOut of each parameter.
   System::Collections::IEnumerator^ enum0 = Myarray->GetEnumerator();
   while ( enum0->MoveNext() )
   {
      ParameterInfo^ Myparam = safe_cast<ParameterInfo^>(enum0->Current);
      Console::Write( "\nFor parameter # {0}, the IsOut is - {1}", Myparam->Position, Myparam->IsOut );
   }

   return 0;
}

/*
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
*/
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 (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
 */
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 

備註

這個方法取決於選擇性的中繼資料旗標。This method depends on an optional metadata flag. 編譯器可以插入此旗標,但編譯器並不需要這麼做。This flag can be inserted by compilers, but the compilers are not obligated to do so.

這個方法會利用 Out 列舉值的旗標 ParameterAttributesThis method utilizes the Out flag of the ParameterAttributes enumerator.

若要取得 ParameterInfo 陣列,請先取得方法或函式,然後再呼叫 MethodBase.GetParametersTo get the ParameterInfo array, first get the method or the constructor and then call MethodBase.GetParameters.

適用於