このパラメータの属性を取得します。
Public Overridable ReadOnly Property Attributes As _
ParameterAttributes
[C#]
public virtual ParameterAttributes Attributes {get;}
[C++]
public: __property virtual ParameterAttributes get_Attributes();
[JScript]
public function get Attributes() : ParameterAttributes;
プロパティ値
このパラメータの属性を表す ParameterAttributes オブジェクト。
解説
AttrsImpl メソッドを利用します。
ParameterInfo 配列を取得するには、最初にメソッドまたはコンストラクタを取得してから MethodBase.GetParameters を呼び出します。
使用例
Imports System
Imports System.Reflection
Imports Microsoft.VisualBasic
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 'MyClass1
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 'Main
End Class 'ParameterInfo_Attributes
[C#]
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);
}
}
[C++]
#using <mscorlib.dll>
using namespace System;
using namespace System::Reflection;
using namespace System::Runtime::InteropServices;
public __gc class MyClass1
{
public:
int MyMethod(int i, [Out] short* j, long* k)
{
*j = 2;
return 0;
}
};
void main()
{
// Get the type.
Type* myType = __typeof(MyClass1);
// Get the method named 'MyMethod' from the type.
MethodBase* myMethodBase = myType->GetMethod(S"MyMethod");
// Get the parameters associated with the method.
ParameterInfo* myParameters[] = myMethodBase->GetParameters();
Console::WriteLine(S"\nThe method {0} has the {1} parameters :",
S"ParameterInfo_Example::MyMethod", __box(myParameters->Length));
// Print the attributes associated with each of the parameters.
for (int i = 0; i < myParameters->Length; i++)
Console::WriteLine(S"\tThe {0} parameter has the attribute : {1}",
__box(i + 1), __box(myParameters[i]->Attributes));
}
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET, Common Language Infrastructure (CLI) Standard
参照
ParameterInfo クラス | ParameterInfo メンバ | System.Reflection 名前空間 | ParameterAttributes