PropertyInfo.GetSetMethod Metod

Definition

Returnerar en MethodInfo som representerar accessorn för den set här egenskapen.

Överlagringar

Name Description
GetSetMethod(Boolean)

När den åsidosättas i en härledd klass returnerar den accessor för den set här egenskapen.

GetSetMethod()

Returnerar den offentliga set accessorn för den här egenskapen.

GetSetMethod(Boolean)

När den åsidosättas i en härledd klass returnerar den accessor för den set här egenskapen.

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

Parametrar

nonPublic
Boolean

Anger om accessorn ska returneras om den inte är offentlig. trueom en icke-offentlig accessor ska returneras. annars . false

Returer

Den här egenskapens Set metod, eller null, som visas i följande tabell.

Värde Tillstånd
Metoden Set för den här egenskapen. Accessorn set är offentlig, ELLER nonPublic är true och accessorn set är icke-offentlig.
null nonPublic är true, men egenskapen är skrivskyddad, ELLER nonPublic är false och set accessorn är icke-offentlig, ELLER så finns det ingen set accessor.

Implementeringar

Undantag

Den begärda metoden är icke-offentlig och anroparen behöver ReflectionPermission inte reflektera över den här icke-offentliga metoden.

Exempel

I följande exempel visas set accessorn för den angivna egenskapen.

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

Kommentarer

Om du vill använda GetSetMethod metoden hämtar du först klassen Type. TypeFrån hämtar du PropertyInfo. PropertyInfoFrån använder du GetSetMethod -metoden.

Gäller för

GetSetMethod()

Returnerar den offentliga set accessorn för den här egenskapen.

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

Returer

Objektet MethodInfo som representerar metoden för den Set här egenskapen om set accessorn är offentlig eller null om set accessorn inte är offentlig.

Implementeringar

Kommentarer

Det här är en bekvämlighetsmetod som tillhandahåller en implementering för den abstrakta GetSetMethod metoden med parametern inställd på nonPublicfalse.

Om du vill använda GetSetMethod metoden hämtar du först klassen Type. TypeFrån hämtar du PropertyInfo. PropertyInfoFrån använder du GetSetMethod -metoden.

Gäller för