PropertyInfo.GetSetMethod 메서드

정의

이 속성에 대한 MethodInfo 접근자를 나타내는 set를 반환합니다.Returns a MethodInfo representing the set accessor for this property.

오버로드

GetSetMethod(Boolean)

파생 클래스에서 재정의되는 경우 이 속성에 대한 set 접근자를 반환합니다.When overridden in a derived class, returns the set accessor for this property.

GetSetMethod()

이 속성의 public set 접근자를 반환합니다.Returns the public set accessor for this property.

GetSetMethod(Boolean)

파생 클래스에서 재정의되는 경우 이 속성에 대한 set 접근자를 반환합니다.When overridden in a derived class, returns the set accessor for this property.

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이 아닌 경우 접근자를 반환할지 여부를 나타냅니다.Indicates whether the accessor should be returned if it is non-public. public이 아닌 접근자를 반환해야 할 경우 true이고, 그러지 않은 경우 false입니다.true if a non-public accessor is to be returned; otherwise, false.

반환

다음 표에 표시된 것처럼 이 속성의 Set 메서드 또는 null입니다.This property's Set method, or null, as shown in the following table.

Value 조건Condition
이 속성에 대한 Set 메서드입니다.The Set method for this property. set 접근자가 public인 경우입니다.The set accessor is public. 또는-or- nonPublictrue이며 set 접근자는 public이 아닙니다.nonPublic is true and the set accessor is non-public.
nullnonPublictrue이지만 이 속성은 읽기 전용입니다.nonPublic is true, but the property is read-only. 또는-or- nonPublicfalse이며 set 접근자는 public이 아닙니다.nonPublic is false and the set accessor is non-public. 또는-or- set 접근자가 없습니다.There is no set accessor.

구현

예외

요청된 메서드가 public이 아니고 호출자에 이 public이 아닌 메서드에 반영할 ReflectionPermission이 없습니다.The requested method is non-public and the caller does not have ReflectionPermission to reflect on this non-public method.

예제

다음 예에서는 지정 된 속성에 대 한 set 접근자를 표시 합니다.The following example displays the set accessor for the specified property.

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를 가져옵니다.To use the GetSetMethod method, first get the class Type. Type에서 PropertyInfo를 가져옵니다.From the Type, get the PropertyInfo. PropertyInfo에서 GetSetMethod 메서드를 사용 합니다.From the PropertyInfo, use the GetSetMethod method.

GetSetMethod()

이 속성의 public set 접근자를 반환합니다.Returns the public set accessor for this property.

public:
 System::Reflection::MethodInfo ^ GetSetMethod();
public:
 virtual 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 접근자가 public인 경우 이 속성에 대한 Set 메서드를 나타내는 set 개체입니다. 또는 null 접근자가 public이 아니면 set입니다.The MethodInfo object representing the Set method for this property if the set accessor is public, or null if the set accessor is not public.

구현

설명

false로 설정 된 nonPublic 매개 변수를 사용 하 여 추상 GetSetMethod 메서드에 대 한 구현을 제공 하는 편리한 메서드입니다.This is a convenience method that provides an implementation for the abstract GetSetMethod method with the nonPublic parameter set to false.

GetSetMethod 메서드를 사용 하려면 먼저 클래스 Type를 가져옵니다.To use the GetSetMethod method, first get the class Type. Type에서 PropertyInfo를 가져옵니다.From the Type, get the PropertyInfo. PropertyInfo에서 GetSetMethod 메서드를 사용 합니다.From the PropertyInfo, use the GetSetMethod method.

적용 대상