ParameterInfo.Name プロパティ
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
パラメーターの名前を取得します。
public:
virtual property System::String ^ Name { System::String ^ get(); };
public virtual string Name { get; }
public virtual string? Name { get; }
member this.Name : string
Public Overridable ReadOnly Property Name As String
プロパティ値
このパラメーターの簡易名。
例
次の例では、メソッドのパラメーターのオブジェクトを取得 ParameterInfo し、 プロパティを Name 使用してパラメーター名を取得する方法を示します。
using System;
using System.Reflection;
class parminfo
{
public static void mymethod (
int int1m, out string str2m, ref string str3m)
{
str2m = "in mymethod";
}
public static int Main(string[] args)
{
Console.WriteLine("\nReflection.Parameterinfo");
//Get the ParameterInfo parameter of a function.
//Get the type.
Type Mytype = Type.GetType("parminfo");
//Get and display the method.
MethodBase Mymethodbase = Mytype.GetMethod("mymethod");
Console.Write("\nMymethodbase = " + Mymethodbase);
//Get the ParameterInfo array.
ParameterInfo[] Myarray = Mymethodbase.GetParameters();
//Get and display the name of each parameter.
foreach (ParameterInfo Myparam in Myarray)
{
Console.Write ("\nFor parameter # " + Myparam.Position
+ ", the Name is - " + Myparam.Name);
}
return 0;
}
}
/*
This code produces the following output:
Reflection.ParameterInfo
Mymethodbase
= Void mymethod (int, System.String ByRef, System.String ByRef)
For parameter # 0, the Name is - int1m
For parameter # 1, the Name is - str2m
For parameter # 2, the Name is - str3m
*/
Imports System.Reflection
Class parminfo
Public Shared Sub mymethod(int1m As Integer, ByRef str2m As String, _
ByRef str3m As String)
str2m = "in mymethod"
End Sub
Public Shared Function Main() As Integer
Console.WriteLine(ControlChars.CrLf + "Reflection.Parameterinfo")
'Get the ParameterInfo parameter of a function.
'Get the type.
Dim Mytype As Type = Type.GetType("parminfo")
'Get and display the method.
Dim Mymethodbase As MethodBase = Mytype.GetMethod("mymethod")
Console.Write(ControlChars.CrLf _
+ "Mymethodbase = " + Mymethodbase.ToString())
'Get the ParameterInfo array.
Dim Myarray As ParameterInfo() = Mymethodbase.GetParameters()
'Get and display the name of each parameter.
Dim Myparam As ParameterInfo
For Each Myparam In Myarray
Console.Write(ControlChars.CrLf _
+ "For parameter # " + Myparam.Position.ToString() _
+ ", the Name is - " + Myparam.Name)
Next Myparam
Return 0
End Function
End Class
' This code produces the following output:
'
' Reflection.ParameterInfo
'
' Mymethodbase
' = Void mymethod (Int32, System.String ByRef, System.String ByRef)
' For parameter # 0, the Name is - int1m
' For parameter # 1, the Name is - str2m
' For parameter # 2, the Name is - str3m
注釈
このプロパティは、保護された NameImpl フィールドを利用し、すべてのコンパイラで使用できない可能性があるオプションのメタデータ フラグに依存します。
配列を ParameterInfo 取得するには、まず メソッドまたはコンストラクターを取得してから、 メソッドを MethodBase.GetParameters 呼び出します。
警告
これが ParameterInfo 戻り値を表す場合 (つまり、 プロパティを使用 MethodInfo.ReturnParameter して取得された場合)、このプロパティは になります null
。