ParameterInfo.Name 속성

정의

매개 변수의 이름을 가져옵니다.

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 namespace System;
using namespace System::Reflection;
using namespace System::Runtime::InteropServices;
public ref class parminfo
{
public:
   static void mymethod( int int1m, [Out]interior_ptr<String^> str2m, interior_ptr<String^> str3m )
   {
       *str2m = "in mymethod";
   }

};

int main()
{
   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 = {0}", Mymethodbase );
   
   //Get the ParameterInfo array.
   array<ParameterInfo^>^Myarray = Mymethodbase->GetParameters();
   
   //Get and display the name of each parameter.
   System::Collections::IEnumerator^ enum0 = Myarray->GetEnumerator();
   while ( enum0->MoveNext() )
   {
      ParameterInfo^ Myparam = safe_cast<ParameterInfo^>(enum0->Current);
      Console::Write( "\nFor parameter # {0}, the Name is - {1}", Myparam->Position, Myparam->Name );
   }

   return 0;
}

/*
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
*/
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.

적용 대상