ParameterAttributes Wyliczenie

Definicja

Definiuje atrybuty, które mogą być skojarzone z parametrem. Są one zdefiniowane w pliku CorHdr.h.

To wyliczenie obsługuje bitową kombinację jego wartości składowych.

C#
[System.Flags]
public enum ParameterAttributes
C#
[System.Flags]
[System.Serializable]
public enum ParameterAttributes
C#
[System.Flags]
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public enum ParameterAttributes
Dziedziczenie
ParameterAttributes
Atrybuty

Pola

Nazwa Wartość Opis
HasDefault 4096

Określa, że parametr ma wartość domyślną.

HasFieldMarshal 8192

Określa, że parametr ma informacje dotyczące marshalingu pól.

In 1

Określa, że parametr jest parametrem wejściowym.

Lcid 4

Określa, że parametr jest identyfikatorem ustawień regionalnych (lcid).

None 0

Określa, że nie ma atrybutu parametru.

Optional 16

Określa, że parametr jest opcjonalny.

Out 2

Określa, że parametr jest parametrem wyjściowym.

Reserved3 16384

Zarezerwowany.

Reserved4 32768

Zarezerwowany.

ReservedMask 61440

Określa, że parametr jest zarezerwowany.

Retval 8

Określa, że parametr jest wartością zwracaną.

Przykłady

Poniższy przykład przedstawia atrybuty określonego parametru.

C#
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;
    }
}

Uwagi

Aby uzyskać ParameterAttributes wartość, najpierw pobierz element Type. Z poziomu metody Typepobierz tablicę ParameterInfo . Wartość ParameterAttributes znajduje się w tablicy.

Te wartości modułu wyliczającego są zależne od opcjonalnych metadanych. Nie wszystkie atrybuty są dostępne we wszystkich kompilatorach. Zapoznaj się z odpowiednimi instrukcjami kompilatora, aby określić, które wartości wyliczone są dostępne.

Dotyczy

Produkt Wersje
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0