PropertyInfo.GetSetMethod Yöntem

Tanım

Bu özellik için erişimciyi set temsil eden bir MethodInfo döndürür.

Aşırı Yüklemeler

GetSetMethod(Boolean)

Türetilmiş bir sınıfta geçersiz kılındığında, bu özelliğin erişimcisini set döndürür.

GetSetMethod()

Bu özellik için ortak set erişimciyi döndürür.

GetSetMethod(Boolean)

Kaynak:
PropertyInfo.cs
Kaynak:
PropertyInfo.cs
Kaynak:
PropertyInfo.cs

Türetilmiş bir sınıfta geçersiz kılındığında, bu özelliğin erişimcisini set döndürür.

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

Parametreler

nonPublic
Boolean

Ortak olmayan erişimcinin döndürülmesi gerekip gerekmediğini gösterir. true ortak olmayan bir erişimci döndürülecekse; aksi takdirde , false.

Döndürülenler

Bu özelliğin Set yöntemi veya nullaşağıdaki tabloda gösterildiği gibi .

Değer Koşul
Bu özelliğin Set yöntemi. Erişimci set genel, YADA nonPublic , true erişimci set ise genel değil.
null nonPublicşeklindedirtrue, ancak özellik salt okunur veya falseset veya nonPublic erişimci ortak değildir veya erişimci yokturset.

Uygulamalar

Özel durumlar

İstenen yöntem genel değil ve çağıranın bu genel olmayan yöntemi yansıtması gerekmez ReflectionPermission .

Örnekler

Aşağıdaki örnek, belirtilen özelliğin set erişimcisini görüntüler.

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

Açıklamalar

yöntemini kullanmak GetSetMethod için önce sınıfını Typealın. içinden Typeöğesini alın PropertyInfo. içinden PropertyInfoyöntemini kullanın GetSetMethod .

Şunlara uygulanır

.NET 9 ve diğer sürümler
Ürün Sürümler
.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()

Kaynak:
PropertyInfo.cs
Kaynak:
PropertyInfo.cs
Kaynak:
PropertyInfo.cs

Bu özellik için ortak set erişimciyi döndürür.

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

Döndürülenler

Erişimci MethodInfo ortaksa set veya null erişimci ortak değilse, bu özelliğin yöntemini temsil eden Setset nesne.

Uygulamalar

Açıklamalar

Bu, parametresi olarak ayarlanmış soyut GetSetMethod yöntem için bir uygulama sağlayan bir kolaylık yöntemidir nonPublicfalse.

yöntemini kullanmak GetSetMethod için önce sınıfını Typealın. içinden Typeöğesini alın PropertyInfo. içinden PropertyInfoyöntemini kullanın GetSetMethod .

Şunlara uygulanır

.NET 9 ve diğer sürümler
Ürün Sürümler
.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