ParameterAttributes 列舉

定義

定義可以與參數相關聯的屬性。 這些都在 CorHdr.h 中定義。

此列舉支援其成員值的位元組合。

public enum class ParameterAttributes
[System.Flags]
public enum ParameterAttributes
[System.Flags]
[System.Serializable]
public enum ParameterAttributes
[System.Flags]
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public enum ParameterAttributes
[<System.Flags>]
type ParameterAttributes = 
[<System.Flags>]
[<System.Serializable>]
type ParameterAttributes = 
[<System.Flags>]
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type ParameterAttributes = 
Public Enum ParameterAttributes
繼承
ParameterAttributes
屬性

欄位

HasDefault 4096

指定此參數具有預設值。

HasFieldMarshal 8192

指定參數具有欄位封送處理 (Marshaling) 資訊。

In 1

指定參數為輸入參數。

Lcid 4

指定參數為地區設定識別項 (Locale Identifier,LCID)。

None 0

指定沒有參數屬性。

Optional 16

指定參數為選擇項。

Out 2

指定參數為輸出參數。

Reserved3 16384

保留的。

Reserved4 32768

保留的。

ReservedMask 61440

指定參數為保留的。

Retval 8

指定參數為傳回值。

範例

下列範例會顯示指定參數的屬性。

using namespace System;
using namespace System::Reflection;
using namespace System::Runtime::InteropServices;
public ref class paramatt
{
public:
   static void mymethod( String^ str1, [Out]interior_ptr<String^> str2, interior_ptr<String^> str3 )
   {
       *str2 = "string";
   }

};

int main()
{
   Console::WriteLine( "\nReflection.ParameterAttributes" );
   
   // Get the Type and the method.
   Type^ Mytype = Type::GetType( "paramatt" );
   MethodBase^ Mymethodbase = Mytype->GetMethod( "mymethod" );
   
   // Display the method.
   Console::Write( "\nMymethodbase = {0}", Mymethodbase );
   
   // Get the ParameterInfo array.
   array<ParameterInfo^>^Myarray = Mymethodbase->GetParameters();
   
   // Get and display the attributes for the second parameter.
   ParameterAttributes Myparamattributes = Myarray[ 1 ]->Attributes;
   Console::Write( "\nFor the second parameter:\nMyparamattributes = {0}, which is an {1}", (int)Myparamattributes, Myparamattributes );
   return 0;
}
using System;
using System.Reflection;

class paramatt
{
    public static void mymethod (string str1, out string str2, ref string str3)
    {
        str2 = "string";
    }

    public static int Main(string[] args)
    {
        Console.WriteLine("\nReflection.ParameterAttributes");

        // Get the Type and the method.

        Type Mytype = Type.GetType("paramatt");
        MethodBase Mymethodbase = Mytype.GetMethod("mymethod");

        // Display the method.
        Console.Write("\nMymethodbase = " + Mymethodbase);

        // Get the ParameterInfo array.
        ParameterInfo[] Myarray = Mymethodbase.GetParameters();

        // Get and display the attributes for the second parameter.
        ParameterAttributes Myparamattributes = Myarray[1].Attributes;

        Console.Write("\nFor the second parameter:\nMyparamattributes = "
            + (int) Myparamattributes
            + ", which is an "
            + Myparamattributes.ToString());

        return 0;
    }
}
Imports System.Reflection

Class paramatt

    Public Shared Sub mymethod(ByVal str1 As String, ByRef str2 As String, _
    ByRef str3 As String)
        str2 = "string"
    End Sub

    Public Shared Function Main() As Integer
        Console.WriteLine(ControlChars.CrLf + "Reflection.ParameterAttributes")

        ' Get the Type and the method.
        Dim Mytype As Type = Type.GetType("paramatt")
        Dim Mymethodbase As MethodBase = Mytype.GetMethod("mymethod")

        ' Display the method.
        Console.WriteLine("Mymethodbase = " + Mymethodbase.ToString())

        ' Get the ParameterInfo array.
        Dim Myarray As ParameterInfo() = Mymethodbase.GetParameters()

        ' Get and display the attributes for the second parameter.
        Dim Myparamattributes As ParameterAttributes = Myarray(1).Attributes

        Console.WriteLine("For the second parameter:" + ControlChars.CrLf _
           + "Myparamattributes = " + CInt(Myparamattributes).ToString() _
           + ", which is a " + Myparamattributes.ToString())

        Return 0
    End Function
End Class

備註

若要取得 ParameterAttributes 值,請先取得 TypeType從 取得 ParameterInfo 陣列。 值 ParameterAttributes 位於陣列內。

這些列舉值相依于選擇性中繼資料。 並非所有屬性都可從所有編譯器取得。 請參閱適當的編譯器指示,以判斷有哪些列舉值可供使用。

適用於