ParameterAttributes ParameterAttributes ParameterAttributes ParameterAttributes Enum

定义

定义可以与参数相关联的属性。Defines the attributes that can be associated with a parameter. 这些属性在 CorHdr.h 中进行定义。These are defined in CorHdr.h.

此枚举有一个 FlagsAttribute 属性,允许按位组合成员值。

public enum class ParameterAttributes
[System.Flags]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public enum ParameterAttributes
type ParameterAttributes = 
Public Enum ParameterAttributes
继承
ParameterAttributesParameterAttributesParameterAttributesParameterAttributes
属性

字段

HasDefault HasDefault HasDefault HasDefault 4096

指定参数具有默认值。Specifies that the parameter has a default value.

HasFieldMarshal HasFieldMarshal HasFieldMarshal HasFieldMarshal 8192

指定该参数具有字段封送处理信息。Specifies that the parameter has field marshaling information.

In In In In 1

指定该参数是一个输入参数。Specifies that the parameter is an input parameter.

Lcid Lcid Lcid Lcid 4

指定该参数是一个区域设置标识符 (lcid)。Specifies that the parameter is a locale identifier (lcid).

None None None None 0

指定不存在参数属性。Specifies that there is no parameter attribute.

Optional Optional Optional Optional 16

指定参数为可选。Specifies that the parameter is optional.

Out Out Out Out 2

指定该参数是一个输出参数。Specifies that the parameter is an output parameter.

Reserved3 Reserved3 Reserved3 Reserved3 16384

保留。Reserved.

Reserved4 Reserved4 Reserved4 Reserved4 32768

保留。Reserved.

ReservedMask ReservedMask ReservedMask ReservedMask 61440

指定该参数是保留的。Specifies that the parameter is reserved.

Retval Retval Retval Retval 8

指定该参数是一个返回值。Specifies that the parameter is a return value.

示例

下面的示例显示指定的参数的属性。The following example displays the attributes of the specified parameter.

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
Imports System.Reflection
Imports Microsoft.VisualBasic

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值时,请首先获取TypeTo get the ParameterAttributes value, first get the Type. Type,获取ParameterInfo数组。From the Type, get the ParameterInfo array. ParameterAttributes值是数组中。The ParameterAttributes value is within the array.

这些枚举器值都依赖于可选元数据。These enumerator values are dependent on optional metadata. 并非所有属性都将所有编译器中可用。Not all attributes are available from all compilers. 请参阅相应的编译器指令,若要确定可用的枚举的值。See the appropriate compiler instructions to determine which enumerated values are available.

适用于