ParameterAttributes 枚举

定义

定义可以与参数相关联的属性。 这些属性在 CorHdr.h 中进行定义。

此枚举支持其成员值的按位组合。

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
继承
ParameterAttributes
属性

字段

名称 说明
HasDefault 4096

指定参数具有默认值。

HasFieldMarshal 8192

指定该参数具有字段封送处理信息。

In 1

指定该参数是一个输入参数。

Lcid 4

指定该参数是一个区域设置标识符 (lcid)。

None 0

指定不存在参数属性。

Optional 16

指定参数为可选。

Out 2

指定该参数是一个输出参数。

Reserved3 16384

保留。

Reserved4 32768

保留。

ReservedMask 61440

指定该参数是保留的。

Retval 8

指定该参数是一个返回值。

示例

以下示例显示指定参数的属性。

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

注解

若要获取 ParameterAttributes 值,请先获取 Type。 从 中 Type获取 ParameterInfo 数组。 值 ParameterAttributes 在 数组内。

这些枚举器值依赖于可选的元数据。 并非所有属性都可用于所有编译器。 请参阅相应的编译器说明,以确定哪些枚举值可用。

适用于

产品 版本
.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