언어

PropertyInfo.GetSetMethod 메서드

정의

이 속성의 MethodInfoset 접근자를 나타내는 값을 반환합니다.

오버로드

Name Description
GetSetMethod(Boolean)

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

GetSetMethod()

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

GetSetMethod(Boolean)

Source:
PropertyInfo.cs
Source:
PropertyInfo.cs
Source:
PropertyInfo.cs
Source:
PropertyInfo.cs
Source:
PropertyInfo.cs

파생 클래스에서 재정의되는 경우 이 속성의 접근자를 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이 아닌 경우 반환해야 하는지 여부를 나타냅니다. truepublic이 아닌 접근자가 반환되면 이고, 그렇지 않으면 . false

반품

다음 표와 같이 이 속성의 Set 메서드 또는 null

값 조건
이 Set 속성에 대한 메서드입니다. set 접근자가 public이고 OR nonPublic 이고 true 접근자가 set public이 아닌 경우
null nonPublic 가 true있지만 속성이 읽기 전용이고 OR nonPublic 이고 false 접근자가 set public이 아니거나 접근자가 없습니다 set .

구현

예외

요청된 메서드가 public이 아니고 호출자가 이 비공용 메서드를 반영할 필요가 ReflectionPermission 없습니다.

예제

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

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()

Source:
PropertyInfo.cs
Source:
PropertyInfo.cs
Source:
PropertyInfo.cs
Source:
PropertyInfo.cs
Source:
PropertyInfo.cs

이 속성의 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 접근자가 public이거나 Set 접근자가 set public이 아닌 경우 null 이 속성의 메서드를 set 나타내는 개체입니다.

구현

설명

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

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

적용 대상