ParameterInfo.Attributes 속성

정의

이 매개 변수에 대한 특성을 가져옵니다

public:
 virtual property System::Reflection::ParameterAttributes Attributes { System::Reflection::ParameterAttributes get(); };
public virtual System.Reflection.ParameterAttributes Attributes { get; }
member this.Attributes : System.Reflection.ParameterAttributes
Public Overridable ReadOnly Property Attributes As ParameterAttributes

속성 값

이 매개 변수에 대한 특성을 나타내는 ParameterAttributes 개체입니다.

예제

다음 예제에서는 세 개의 매개 변수를 사용하여 메서드를 정의합니다. 속성을 Attributes 사용하여 두 번째 매개 변수의 특성을 가져와 콘솔에 표시합니다.

using namespace System;
using namespace System::Reflection;
using namespace System::Runtime::InteropServices;
public ref class MyClass1
{
public:
   int MyMethod( int i, [Out]short * j, long * k )
   {
       *j = 2;
      return 0;
   }

};

void main()
{
   // Get the type. 
   Type^ myType = MyClass1::typeid;

   // Get the method named 'MyMethod' from the type.
   MethodBase^ myMethodBase = myType->GetMethod( "MyMethod" );

   // Get the parameters associated with the method.
   array<ParameterInfo^>^myParameters = myMethodBase->GetParameters();
   Console::WriteLine( "\nThe method {0} has the {1} parameters :", "ParameterInfo_Example::MyMethod", myParameters->Length );

   // Print the attributes associated with each of the parameters.
   for ( int i = 0; i < myParameters->Length; i++ )
      Console::WriteLine( "\tThe {0} parameter has the attribute : {1}", i + 1, myParameters[ i ]->Attributes );
}
using System;
using System.Reflection;
public class MyClass1
{
   public int MyMethod( int i, out short j, ref long k)
   {
      j = 2;
      return 0;
   }
}

public class ParameterInfo_Attributes
{
   public static void Main()
   {
      // Get the type.
      Type myType = typeof(MyClass1);
      // Get the method named 'MyMethod' from the type.
      MethodBase myMethodBase = myType.GetMethod("MyMethod");
      // Get the parameters associated with the method.
      ParameterInfo[] myParameters = myMethodBase.GetParameters();
      Console.WriteLine("\nThe method {0} has the {1} parameters :",
                          "ParameterInfo_Example.MyMethod", myParameters.Length);
      // Print the attributes associated with each of the parameters.
      for(int i = 0; i < myParameters.Length; i++)
         Console.WriteLine("\tThe {0} parameter has the attribute : {1}",
                                             i + 1, myParameters[i].Attributes);
   }
}
Imports System.Reflection

Public Class MyClass1
   
   Public Function MyMethod(i As Integer, ByRef j As Short, ByRef k As Long) As Integer
      j = 2
      Return 0
   End Function 'MyMethod
End Class

Public Class ParameterInfo_Attributes
   
   Public Shared Sub Main()
      ' Get the type. 
      Dim myType As Type = GetType(MyClass1)
      ' Get the method named 'MyMethod' from the type.
      Dim myMethodBase As MethodBase = myType.GetMethod("MyMethod")
      ' Get the parameters associated with the method.
      Dim myParameters As ParameterInfo() = myMethodBase.GetParameters()
      Console.WriteLine(ControlChars.Cr + "The method {0} has the {1} parameters :", "ParameterInfo_Example.MyMethod", myParameters.Length)
      ' Print the attributes associated with each of the parameters.
      Dim i As Integer
      For i = 0 To myParameters.Length - 1
         Console.WriteLine(ControlChars.Tab + "The {0} parameter has the attribute : {1}", i + 1, myParameters(i).Attributes)
      Next i
   End Sub
End Class

설명

이 메서드는 메서드를 AttrsImpl 활용합니다.

배열을 ParameterInfo 얻으려면 먼저 메서드 또는 생성자를 가져와서 를 호출 MethodBase.GetParameters합니다.

적용 대상

추가 정보