Nyelv

PropertyInfo.GetSetMethod Metódus

Definíció

A tulajdonsághoz tartozó tartozékot MethodInfo adja set vissza.

Túlterhelések

Name Description
GetSetMethod(Boolean)

Ha egy származtatott osztályban felül van bírálva, a tulajdonsághoz tartozó tartozékot set adja vissza.

GetSetMethod()

A tulajdonság nyilvános set tartozékát adja vissza.

GetSetMethod(Boolean)

Forrás:
PropertyInfo.cs
Forrás:
PropertyInfo.cs
Forrás:
PropertyInfo.cs
Forrás:
PropertyInfo.cs
Forrás:
PropertyInfo.cs

Ha egy származtatott osztályban felül van bírálva, a tulajdonsághoz tartozó tartozékot set adja vissza.

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

Paraméterek

nonPublic
Boolean

Jelzi, hogy a tartozékot vissza kell-e adni, ha nem nyilvános. truenem nyilvános tartozék visszaadása esetén; egyéb esetben. false

Válaszok

Ennek a tulajdonságnak a metódusa Set , vagy nullaz alábbi táblázatban látható módon.

Érték Feltétel
A Set tulajdonság metódusa. A set tartozék nyilvános, VAGY nonPublic , true és a set tartozék nem nyilvános.
null nonPublic az true, de a tulajdonság írásvédett, VAGY nonPublic az false , és a set tartozék nem nyilvános, VAGY nincs set tartozék.

Megvalósítás

Kivételek

A kért metódus nem nyilvános, és a hívónak nem kell ReflectionPermission tükröznie ezt a nem nyilvános metódust.

Példák

Az alábbi példa a set megadott tulajdonsághoz tartozó tartozékot jeleníti meg.

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

Megjegyzések

A metódus használatához GetSetMethod először szerezze be az osztályt Type. TypeA helyről szerezze be a PropertyInfo. Használja a PropertyInfometódust.GetSetMethod

A következőre érvényes:

GetSetMethod()

Forrás:
PropertyInfo.cs
Forrás:
PropertyInfo.cs
Forrás:
PropertyInfo.cs
Forrás:
PropertyInfo.cs
Forrás:
PropertyInfo.cs

A tulajdonság nyilvános set tartozékát adja vissza.

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

Válaszok

A MethodInfo tulajdonság metódusát Set képviselő objektum, ha a set tartozék nyilvános, vagy null ha a set tartozék nem nyilvános.

Megvalósítás

Megjegyzések

Ez egy kényelmi módszer, amely az absztrakt GetSetMethod metódus implementálását biztosítja a nonPublic paraméter beállításával false.

A metódus használatához GetSetMethod először szerezze be az osztályt Type. TypeA helyről szerezze be a PropertyInfo. Használja a PropertyInfometódust.GetSetMethod

A következőre érvényes: