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
屬性

欄位

名稱 Description
None 0

指定不存在參數屬性。

In 1

指定參數為輸入參數。

Out 2

指定參數為輸出參數。

Lcid 4

指定參數為區域識別碼(lcid)。

Retval 8

指定參數為回傳值。

Optional 16

指定參數為可選。

HasDefault 4096

指定參數有預設值。

HasFieldMarshal 8192

指定參數包含場域編制資訊。

Reserved3 16384

已保留。

Reserved4 32768

已保留。

ReservedMask 61440

指定參數為保留值。

範例

以下範例展示指定參數的屬性。

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 該值,首先取得 Type。 從 Type,取得 ParameterInfo 陣列。 ParameterAttributes數值就在陣列內。

這些列舉器值依賴於可選的元資料。 並非所有屬性都能從所有編譯器取得。 請參閱適當的編譯器指令以判斷可用的列舉值。

適用於