PropertyInfo.GetSetMethod PropertyInfo.GetSetMethod PropertyInfo.GetSetMethod PropertyInfo.GetSetMethod Method

Definición

Devuelve MethodInfo que representa el descriptor de acceso set de esta propiedad.Returns a MethodInfo representing the set accessor for this property.

Sobrecargas

GetSetMethod(Boolean) GetSetMethod(Boolean) GetSetMethod(Boolean) GetSetMethod(Boolean)

Cuando se reemplaza en una clase derivada, devuelve el descriptor de acceso set de esta propiedad.When overridden in a derived class, returns the set accessor for this property.

GetSetMethod() GetSetMethod() GetSetMethod() GetSetMethod()

Devuelve el descriptor de acceso set público de esta propiedad.Returns the public set accessor for this property.

GetSetMethod(Boolean) GetSetMethod(Boolean) GetSetMethod(Boolean) GetSetMethod(Boolean)

Cuando se reemplaza en una clase derivada, devuelve el descriptor de acceso set de esta propiedad.When overridden in a derived class, returns the set accessor for this property.

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

Parámetros

nonPublic
Boolean Boolean Boolean Boolean

Indica si se debe devolver el descriptor de acceso si es no público.Indicates whether the accessor should be returned if it is non-public. true si se debe devolver un descriptor de acceso no público; de lo contrario, false.true if a non-public accessor is to be returned; otherwise, false.

Devoluciones

El método Set de esta propiedad, o null, como se muestra en la tabla siguiente.This property's Set method, or null, as shown in the following table.

ValorValue CondiciónCondition
El método Set de esta propiedad.The Set method for this property. El descriptor de acceso set es público.The set accessor is public. O bien-or- El valor de nonPublic es true y el descriptor de acceso set no es público.nonPublic is true and the set accessor is non-public.
nullnonPublic es true, pero la propiedad es de sólo lectura.nonPublic is true, but the property is read-only. O bien-or- El valor de nonPublic es false y el descriptor de acceso set no es público.nonPublic is false and the set accessor is non-public. O bien-or- No hay descriptor de acceso set.There is no set accessor.

Implementaciones

Excepciones

El método solicitado no es público y el autor de llamada no tiene ReflectionPermission para reflejar en este método no público.The requested method is non-public and the caller does not have ReflectionPermission to reflect on this non-public method.

Ejemplos

El ejemplo siguiente se muestra el set descriptor de acceso para la propiedad especificada.The following example displays the set accessor for the specified property.

using namespace System;
using namespace System::Reflection;

// Define a property.
public ref class Myproperty
{
private:
   String^ caption;

public:

   property String^ Caption 
   {
      String^ get()
      {
         return caption;
      }

      void set( String^ value )
      {
         if ( caption != value )
         {
            caption = value;
         }
      }

   }

};

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 {0} returns a {1}", Mypropertyinfoa->Name, Mygetmethodinfoa->ReturnType );
   MethodInfo^ Mygetmethodinfob = Mypropertyinfob->GetSetMethod();
   Console::Write( "\nSetAccessor for {0} returns a {1}", Mypropertyinfob->Name, Mygetmethodinfob->ReturnType );
   
   // Display the GetSetMethod without using the MethodInfo.
   Console::Write( "\n\n{0}.{1} GetSetMethod - {2}", MyTypea->FullName, Mypropertyinfoa->Name, Mypropertyinfoa->GetSetMethod() );
   Console::Write( "\n{0}.{1} GetSetMethod - {2}", MyTypeb->FullName, Mypropertyinfob->Name, Mypropertyinfob->GetSetMethod() );
   return 0;
}

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
Imports System.Reflection
Imports Microsoft.VisualBasic

' 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

Comentarios

Para usar el GetSetMethod método, obtenga primero la clase Type.To use the GetSetMethod method, first get the class Type. Desde el Type, obtener el PropertyInfo.From the Type, get the PropertyInfo. Desde el PropertyInfo, utilice el GetSetMethod método.From the PropertyInfo, use the GetSetMethod method.

Seguridad

ReflectionPermission
Cuando se invoca en tiempo de ejecución a través de mecanismos como InvokeMember(String, BindingFlags, Binder, Object, Object[], ParameterModifier[], CultureInfo, String[]).when invoked late-bound through mechanisms such as InvokeMember(String, BindingFlags, Binder, Object, Object[], ParameterModifier[], CultureInfo, String[]). Enumeración asociada: MemberAccess.Associated enumeration: MemberAccess.

GetSetMethod() GetSetMethod() GetSetMethod() GetSetMethod()

Devuelve el descriptor de acceso set público de esta propiedad.Returns the public set accessor for this property.

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

Devoluciones

Objeto MethodInfo que representa el método Set de esta propiedad si el descriptor de acceso set es público, o null si el descriptor de acceso set no es público.The MethodInfo object representing the Set method for this property if the set accessor is public, or null if the set accessor is not public.

Implementaciones

Comentarios

Se trata de un método de conveniencia que proporciona una implementación abstracta GetSetMethod método con el nonPublic parámetro establecido en false.This is a convenience method that provides an implementation for the abstract GetSetMethod method with the nonPublic parameter set to false.

Para usar el GetSetMethod método, obtenga primero la clase Type.To use the GetSetMethod method, first get the class Type. Desde el Type, obtener el PropertyInfo.From the Type, get the PropertyInfo. Desde el PropertyInfo, utilice el GetSetMethod método.From the PropertyInfo, use the GetSetMethod method.

Seguridad

ReflectionPermission
Cuando se invoca en tiempo de ejecución a través de mecanismos como InvokeMember(String, BindingFlags, Binder, Object, Object[], ParameterModifier[], CultureInfo, String[]).when invoked late-bound through mechanisms such as InvokeMember(String, BindingFlags, Binder, Object, Object[], ParameterModifier[], CultureInfo, String[]). Enumeración asociada: MemberAccess.Associated enumeration: MemberAccess.

Se aplica a