PropertyInfo.GetSetMethod Metodo

Definizione

Restituisce un oggetto MethodInfo che rappresenta la set funzione di accesso per questa proprietà.

Overload

Nome Descrizione
GetSetMethod(Boolean)

Quando sottoposto a override in una classe derivata, restituisce la set funzione di accesso per questa proprietà.

GetSetMethod()

Restituisce la funzione di accesso pubblica set per questa proprietà.

GetSetMethod(Boolean)

Quando sottoposto a override in una classe derivata, restituisce la set funzione di accesso per questa proprietà.

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

Parametri

nonPublic
Boolean

Indica se la funzione di accesso deve essere restituita se non è pubblica. true se deve essere restituita una funzione di accesso non pubblica; in caso contrario, false.

Valori restituiti

Metodo di Set questa proprietà o null, come illustrato nella tabella seguente.

Valore Condizione
Metodo Set per questa proprietà. La set funzione di accesso è pubblica, OR nonPublic è true e la set funzione di accesso non è pubblica.
null nonPublic è true, ma la proprietà è di sola lettura, OR nonPublic è false e la set funzione di accesso non è pubblica oppure non è presente alcuna set funzione di accesso.

Implementazioni

Eccezioni

Il metodo richiesto non è pubblico e il chiamante non deve ReflectionPermission riflettere su questo metodo non pubblico.

Esempio

Nell'esempio seguente viene visualizzata la set funzione di accesso per la proprietà specificata.

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

Commenti

Per usare il GetSetMethod metodo , ottenere prima di tutto la classe Type. TypeDa ottenere .PropertyInfo PropertyInfoDa usare il GetSetMethod metodo .

Si applica a

GetSetMethod()

Restituisce la funzione di accesso pubblica set per questa proprietà.

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

Valori restituiti

Oggetto MethodInfo che rappresenta il Set metodo per questa proprietà se la set funzione di accesso è pubblica o null se la set funzione di accesso non è pubblica.

Implementazioni

Commenti

Si tratta di un metodo pratico che fornisce un'implementazione per il metodo astratto GetSetMethod con il nonPublic parametro impostato su false.

Per usare il GetSetMethod metodo , ottenere prima di tutto la classe Type. TypeDa ottenere .PropertyInfo PropertyInfoDa usare il GetSetMethod metodo .

Si applica a