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
Атрибуты

Поля

Имя Значение Описание
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 находится в массиве.

Эти значения перечислителя зависят от необязательных метаданных. Не все атрибуты доступны для всех компиляторов. Ознакомьтесь с соответствующими инструкциями компилятора, чтобы определить, какие перечисленные значения доступны.

Применяется к