PropertyInfo.GetSetMethod Methode

Definition

Gibt eine MethodInfo zurück, die den set-Accessor für diese Eigenschaft darstellt.

Überlädt

GetSetMethod(Boolean)

Gibt beim Überschreiben in einer abgeleiteten Klasse den set-Accessor für diese Eigenschaft zurück.

GetSetMethod()

Gibt den öffentlichen set-Accessor für diese Eigenschaft zurück.

GetSetMethod(Boolean)

Gibt beim Überschreiben in einer abgeleiteten Klasse den set-Accessor für diese Eigenschaft zurück.

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

Parameter

nonPublic
Boolean

Gibt an, ob die Zugriffsmethode zurückgegeben werden soll, wenn sie nicht öffentlich ist. true, wenn ein nicht öffentlicher Accessor zurückgegeben werden soll, andernfalls false.

Gibt zurück

MethodInfo

Die Set-Methode dieser Eigenschaft, oder null, wie in der folgenden Tabelle gezeigt.

Wert Bedingung
Die Set-Methode für diese Eigenschaft. Der set-Accessor ist öffentlich, ODER nonPublic ist true, und der set-Accessor ist nicht öffentlich.
nullnonPublic ist true, aber die Eigenschaft ist schreibgeschützt, ODER nonPublic ist false, und der set-Accessor ist nicht öffentlich, ODER es gibt keinen set-Accessor.

Implementiert

Ausnahmen

Die angeforderte Methode ist nicht öffentlich, und der Aufrufer verfügt nicht über die ReflectionPermission zum Reflektieren dieser nicht öffentlichen Methode.

Beispiele

Im folgenden Beispiel wird der set Accessor für die angegebene Eigenschaft angezeigt.

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

Hinweise

Um die -Methode zu GetSetMethod verwenden, müssen Sie zuerst die -Klasse Type abrufen. Abrufen von aus Type PropertyInfo . Verwenden Sie in PropertyInfo die GetSetMethod -Methode.

Gilt für

GetSetMethod()

Gibt den öffentlichen set-Accessor für diese Eigenschaft zurück.

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

Gibt zurück

MethodInfo

Das MethodInfo-Objekt, das die Set-Methode für diese Eigenschaft darstellt, wenn der set-Accessor öffentlich ist, oder null, wenn der set-Accessor nicht öffentlich ist.

Implementiert

Hinweise

Dies ist eine praktische Methode, die eine Implementierung für die abstrakte GetSetMethod Methode bereitstellt, wobei der nonPublic Parameter auf festgelegt false ist.

Um die -Methode zu GetSetMethod verwenden, müssen Sie zuerst die -Klasse Type abrufen. Abrufen von aus Type PropertyInfo . Verwenden Sie in PropertyInfo die GetSetMethod -Methode.

Gilt für