ParameterAttributes 枚举

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

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

**命名空间:**System.Reflection
**程序集:**mscorlib(在 mscorlib.dll 中)

语法

声明
<SerializableAttribute> _
<ComVisibleAttribute(True)> _
<FlagsAttribute> _
Public Enumeration ParameterAttributes
用法
Dim instance As ParameterAttributes
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
[FlagsAttribute] 
public enum ParameterAttributes
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
[FlagsAttribute] 
public enum class ParameterAttributes
/** @attribute SerializableAttribute() */ 
/** @attribute ComVisibleAttribute(true) */ 
/** @attribute FlagsAttribute() */ 
public enum ParameterAttributes
SerializableAttribute 
ComVisibleAttribute(true) 
FlagsAttribute 
public enum ParameterAttributes

成员

  成员名称 说明
由 .NET Compact Framework 支持 HasDefault 指定该参数有默认值。 
由 .NET Compact Framework 支持 HasFieldMarshal 指定该参数具有字段封送处理信息。 
由 .NET Compact Framework 支持 In 指定该参数是一个输入参数。 
由 .NET Compact Framework 支持 Lcid 指定该参数是一个区域设置标识符 (lcid)。 
由 .NET Compact Framework 支持 None 指定不存在参数属性。 
由 .NET Compact Framework 支持 Optional 指定该参数是可选的。 
由 .NET Compact Framework 支持 Out 指定该参数是一个输出参数。 
由 .NET Compact Framework 支持 Reserved3 保留。 
由 .NET Compact Framework 支持 Reserved4 保留。 
由 .NET Compact Framework 支持 ReservedMask 指定该参数是保留的。 
由 .NET Compact Framework 支持 Retval 指定该参数是一个返回值。 

备注

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

这些枚举数的值依赖于可选的元数据。并非所有属性在所有编译器中都可用。请参见相应的编译器指令以确定可用的枚举数值。

示例

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

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
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;
    }
}
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;
}
import System.*;
import System.Reflection.*;

class Paramatt
{   
    public static void Mymethod(String str1,
        /** @ref
         */ String str2,
        /** @ref
         */ String str3)
    {
        str2 = "string";
    } //Mymethod

    public static void 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].get_Attributes();

        Console.Write(("\nFor the second parameter:\nMyparamattributes = " 
            + (int)(myParamAttributes) + ", which is an " 
            + myParamAttributes.ToString()));
    } //main
} //Paramatt

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

.NET Compact Framework

受以下版本支持:2.0、1.0

请参见

参考

System.Reflection 命名空间