PropertyInfo.GetSetMethod Metoda

Definicja

Zwraca element reprezentujący metodę MethodInfoset dostępu dla tej właściwości.

Przeciążenia

GetSetMethod(Boolean)

Po przesłonięciu w klasie pochodnej metoda zwraca metodę set dostępu dla tej właściwości.

GetSetMethod()

Zwraca publiczny set element dostępu dla tej właściwości.

GetSetMethod(Boolean)

Źródło:
PropertyInfo.cs
Źródło:
PropertyInfo.cs
Źródło:
PropertyInfo.cs

Po przesłonięciu w klasie pochodnej metoda zwraca metodę set dostępu dla tej właściwości.

C#
public abstract System.Reflection.MethodInfo? GetSetMethod (bool nonPublic);
C#
public abstract System.Reflection.MethodInfo GetSetMethod (bool nonPublic);

Parametry

nonPublic
Boolean

Wskazuje, czy akcesor powinien zostać zwrócony, jeśli nie jest publiczny. true w przypadku zwrócenia niepubliczonego dostępu; w przeciwnym razie , false.

Zwraca

Metoda tej właściwości Set lub null, jak pokazano w poniższej tabeli.

Wartość Warunek
Metoda Set dla tej właściwości. Akcesorium set jest publiczne, LUB nonPublic jest true i set akcesorium jest niepublika.
null nonPublic to true, ale właściwość jest tylko do odczytu, LUB nonPublic jest false i set akcesor jest niepublika, LUB nie ma set dostępu.

Implementuje

Wyjątki

Żądana metoda jest niepubliczna, a obiekt wywołujący nie musi ReflectionPermission odzwierciedlać tej metody niepubliczonej.

Przykłady

Poniższy przykład przedstawia metodę set dostępu dla określonej właściwości.

C#
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;
    }
}

Uwagi

Aby użyć GetSetMethod metody , najpierw pobierz klasę Type. W pliku Typepobierz element PropertyInfo. W pliku PropertyInfoużyj GetSetMethod metody .

Dotyczy

.NET 9 i inne wersje
Produkt Wersje
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.5, 1.6, 2.0, 2.1

GetSetMethod()

Źródło:
PropertyInfo.cs
Źródło:
PropertyInfo.cs
Źródło:
PropertyInfo.cs

Zwraca publiczny set element dostępu dla tej właściwości.

C#
public System.Reflection.MethodInfo? GetSetMethod ();
C#
public System.Reflection.MethodInfo GetSetMethod ();

Zwraca

MethodInfo Obiekt reprezentujący metodę Set dla tej właściwości, jeśli set metoda dostępu jest publiczna lub null jeśli metoda dostępu nie jest publicznaset.

Implementuje

Uwagi

Jest to metoda wygody, która zapewnia implementację metody abstrakcyjnej GetSetMethod z parametrem ustawionym nonPublic na false.

Aby użyć GetSetMethod metody , najpierw pobierz klasę Type. W pliku Typepobierz element PropertyInfo. W pliku PropertyInfoużyj GetSetMethod metody .

Dotyczy

.NET 9 i inne wersje
Produkt Wersje
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.5, 1.6, 2.0, 2.1