PropertyInfo.GetSetMethod 메서드

정의

이 속성에 대한 MethodInfo 접근자를 나타내는 set를 반환합니다.

오버로드

GetSetMethod(Boolean)

파생 클래스에서 재정의되는 경우 이 속성에 대한 set 접근자를 반환합니다.

GetSetMethod()

이 속성의 public set 접근자를 반환합니다.

GetSetMethod(Boolean)

파생 클래스에서 재정의되는 경우 이 속성에 대한 set 접근자를 반환합니다.

public:
 abstract System::Reflection::MethodInfo ^ GetSetMethod(bool nonPublic);
public abstract System.Reflection.MethodInfo? GetSetMethod (bool nonPublic);
public abstract System.Reflection.MethodInfo GetSetMethod (bool nonPublic);
abstract member GetSetMethod : bool -> System.Reflection.MethodInfo
Public MustOverride Function GetSetMethod (nonPublic As Boolean) As MethodInfo

매개 변수

nonPublic
Boolean

public이 아닌 경우 접근자를 반환할지 여부를 나타냅니다. public이 아닌 접근자를 반환해야 할 경우 true이고, 그러지 않은 경우 false입니다.

반환

MethodInfo

다음 표에 표시된 것처럼 이 속성의 Set 메서드 또는 null입니다.

조건
이 속성에 대한 Set 메서드입니다. set 접근자가 public이거나 nonPublictrue이고 set 접근자가 non-public입니다.
nullnonPublictrue지만 속성은 읽기 전용이거나, nonPublicfalse이고 set 접근자가 non-public이거나 set 접근자가 없습니다.

구현

예외

요청된 메서드가 public이 아니고 호출자에 이 public이 아닌 메서드에 반영할 ReflectionPermission이 없습니다.

예제

다음 예제에서는 지정된 속성에 set 대한 접근자를 표시합니다.

using namespace System;
using namespace System::Reflection;

// Define a property.
public ref class Myproperty
{
private:
   String^ caption;

public:

   property String^ Caption 
   {
      String^ get()
      {
         return caption;
      }

      void set( String^ value )
      {
         if ( caption != value )
         {
            caption = value;
         }
      }

   }

};

int main()
{
   Console::WriteLine( "\nReflection.PropertyInfo" );
   
   // Get the type and PropertyInfo for two separate properties.
   Type^ MyTypea = Type::GetType( "Myproperty" );
   PropertyInfo^ Mypropertyinfoa = MyTypea->GetProperty( "Caption" );
   Type^ MyTypeb = Type::GetType( "System.Text.StringBuilder" );
   PropertyInfo^ Mypropertyinfob = MyTypeb->GetProperty( "Length" );
   
   // Get and display the GetSetMethod method for each property.
   MethodInfo^ Mygetmethodinfoa = Mypropertyinfoa->GetSetMethod();
   Console::Write( "\nSetAccessor for {0} returns a {1}", Mypropertyinfoa->Name, Mygetmethodinfoa->ReturnType );
   MethodInfo^ Mygetmethodinfob = Mypropertyinfob->GetSetMethod();
   Console::Write( "\nSetAccessor for {0} returns a {1}", Mypropertyinfob->Name, Mygetmethodinfob->ReturnType );
   
   // Display the GetSetMethod without using the MethodInfo.
   Console::Write( "\n\n{0}.{1} GetSetMethod - {2}", MyTypea->FullName, Mypropertyinfoa->Name, Mypropertyinfoa->GetSetMethod() );
   Console::Write( "\n{0}.{1} GetSetMethod - {2}", MyTypeb->FullName, Mypropertyinfob->Name, Mypropertyinfob->GetSetMethod() );
   return 0;
}
using System;
using System.Reflection;

// Define a property.
public class Myproperty
{
    private string caption = "A Default caption";
    public string Caption
    {
        get{return caption;}
        set {if(caption!=value) {caption = value;}
        }
    }
}

class Mypropertyinfo
{
    public static int Main()
    {
        Console.WriteLine ("\nReflection.PropertyInfo");

        // Get the type and PropertyInfo for two separate properties.
        Type MyTypea = Type.GetType("Myproperty");
        PropertyInfo Mypropertyinfoa = MyTypea.GetProperty("Caption");
        Type MyTypeb = Type.GetType("System.Text.StringBuilder");
        PropertyInfo Mypropertyinfob = MyTypeb.GetProperty("Length");
        // Get and display the GetSetMethod method for each property.
        MethodInfo Mygetmethodinfoa = Mypropertyinfoa.GetSetMethod();
        Console.Write ("\nSetAccessor for " + Mypropertyinfoa.Name
            + " returns a " + Mygetmethodinfoa.ReturnType);
        MethodInfo Mygetmethodinfob = Mypropertyinfob.GetSetMethod();
        Console.Write ("\nSetAccessor for " + Mypropertyinfob.Name
            + " returns a " + Mygetmethodinfob.ReturnType);

        // Display the GetSetMethod without using the MethodInfo.
        Console.Write ("\n\n" + MyTypea.FullName + "."
            + Mypropertyinfoa.Name + " GetSetMethod - "
            + Mypropertyinfoa.GetSetMethod());
        Console.Write ("\n" + MyTypeb.FullName + "."
            + Mypropertyinfob.Name + " GetSetMethod - "
            + Mypropertyinfob.GetSetMethod());
        return 0;
    }
}
Imports System.Reflection

' Define a property.
Public Class Myproperty
    Private myCaption As String = "A Default caption"

    Public Property Caption() As String
        Get
            Return myCaption
        End Get
        Set(ByVal Value As String)
            If myCaption <> value Then
                myCaption = value
            End If
        End Set
    End Property
End Class

Class Mypropertyinfo

    Public Shared Function Main() As Integer
        Console.WriteLine(ControlChars.CrLf & "Reflection.PropertyInfo")

        ' Get the type and PropertyInfo for two separate properties.
        Dim MyTypea As Type = Type.GetType("Myproperty")
        Dim Mypropertyinfoa As PropertyInfo = MyTypea.GetProperty("Caption")
        Dim MyTypeb As Type = Type.GetType("System.Text.StringBuilder")
        Dim Mypropertyinfob As PropertyInfo = MyTypeb.GetProperty("Length")
        ' Get and display the GetSetMethod method for each property.
        Dim Mygetmethodinfoa As MethodInfo = Mypropertyinfoa.GetSetMethod()
        Console.WriteLine("SetAccessor for " & Mypropertyinfoa.Name & _
           " returns a " & Mygetmethodinfoa.ReturnType.ToString())
        Dim Mygetmethodinfob As MethodInfo = Mypropertyinfob.GetSetMethod()
        Console.WriteLine("SetAccessor for " & Mypropertyinfob.Name & _
           " returns a " & Mygetmethodinfob.ReturnType.ToString())

        ' Display the GetSetMethod without using the MethodInfo.
        Console.WriteLine(MyTypea.FullName & "." & Mypropertyinfoa.Name & _
           " GetSetMethod - " & Mypropertyinfoa.GetSetMethod().ToString())
        Console.WriteLine(MyTypeb.FullName & "." & Mypropertyinfob.Name & _
           " GetSetMethod - " & Mypropertyinfob.GetSetMethod().ToString())
        Return 0
    End Function
End Class

설명

메서드를 GetSetMethod 사용하려면 먼저 클래스 Type를 가져옵니다. 에서 .TypePropertyInfo PropertyInfo에서 메서드를 GetSetMethod 사용합니다.

적용 대상

GetSetMethod()

이 속성의 public set 접근자를 반환합니다.

public:
 System::Reflection::MethodInfo ^ GetSetMethod();
public:
 virtual System::Reflection::MethodInfo ^ GetSetMethod();
public System.Reflection.MethodInfo? GetSetMethod ();
public System.Reflection.MethodInfo GetSetMethod ();
member this.GetSetMethod : unit -> System.Reflection.MethodInfo
abstract member GetSetMethod : unit -> System.Reflection.MethodInfo
override this.GetSetMethod : unit -> System.Reflection.MethodInfo
Public Function GetSetMethod () As MethodInfo

반환

MethodInfo

MethodInfo 접근자가 public인 경우 이 속성에 대한 Set 메서드를 나타내는 set 개체입니다. 또는 null 접근자가 public이 아니면 set입니다.

구현

설명

이 메서드는 매개 변수가 로 설정된 false추상 GetSetMethod 메서드에 대한 구현을 nonPublic 제공하는 편리한 메서드입니다.

메서드를 GetSetMethod 사용하려면 먼저 클래스 Type를 가져옵니다. 에서 .TypePropertyInfo PropertyInfo에서 메서드를 GetSetMethod 사용합니다.

적용 대상