PropertyInfo.GetSetMethod Método
Definição
Importante
Algumas informações se referem a produtos de pré-lançamento que podem ser substancialmente modificados antes do lançamento. A Microsoft não oferece garantias, expressas ou implícitas, das informações aqui fornecidas.
Retorna um MethodInfo acessador que set representa essa propriedade.
Sobrecargas
| Nome | Description |
|---|---|
| GetSetMethod(Boolean) |
Quando substituído em uma classe derivada, retorna o |
| GetSetMethod() |
Retorna o acessador público |
GetSetMethod(Boolean)
Quando substituído em uma classe derivada, retorna o set acessador dessa propriedade.
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
Indica se o acessador deve ser retornado se não for público.
true se um acessador não público deve ser retornado; caso contrário, false.
Retornos
O método dessa Set propriedade, ou null, conforme mostrado na tabela a seguir.
| Valor | Condição |
|---|---|
O Set método para essa propriedade.
| O set acessador é público, OR nonPublic é true e o set acessador não é público.
|
null |
nonPublic é true, mas a propriedade é somente leitura, OR nonPublic é false e o set acessador não é público, OU não há acessador set .
|
Implementações
Exceções
O método solicitado não é público e o chamador não precisa ReflectionPermission refletir sobre esse método não público.
Exemplos
O exemplo a seguir exibe o set acessador da propriedade especificada.
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
Comentários
Para usar o GetSetMethod método, primeiro obtenha a classe Type.
TypeDo .get the PropertyInfo.
PropertyInfoNo método , use o GetSetMethod método.
Aplica-se a
GetSetMethod()
Retorna o acessador público set dessa propriedade.
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
Retornos
O MethodInfo objeto que representa o Set método dessa propriedade se o set acessador for público ou null se o set acessador não for público.
Implementações
Comentários
Esse é um método de conveniência que fornece uma implementação para o método abstrato GetSetMethod com o nonPublic parâmetro definido como false.
Para usar o GetSetMethod método, primeiro obtenha a classe Type.
TypeDo .get the PropertyInfo.
PropertyInfoNo método , use o GetSetMethod método.