PropertyInfo.GetSetMethod Método
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Devolve a MethodInfo representando o set acessório para esta propriedade.
Sobrecargas
| Name | Description |
|---|---|
| GetSetMethod(Boolean) |
Quando sobrescrito numa classe derivada, devolve o |
| GetSetMethod() |
Devolve o acessório público |
GetSetMethod(Boolean)
Quando sobrescrito numa classe derivada, devolve o set acessório para esta 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 acessório deve ser devolvido se for não público.
true se um acessório não público for devolvido; caso contrário, false.
Devoluções
O método desta Set propriedade, ou null, como mostrado na tabela seguinte.
| Valor | Condição |
|---|---|
O Set método para esta propriedade.
| O set acessório é público, OU nonPublic é true e o set acessório é não público.
|
null |
nonPublic é true, mas a propriedade é de apenas leitura, OU nonPublic é false e o set acessor é não público, OU não set existe acessório.
|
Implementações
Exceções
O método solicitado é privado e o interlocutor não tem ReflectionPermission de refletir sobre este método privado.
Exemplos
O exemplo seguinte mostra o set acessório para a 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
Observações
Para usar o GetSetMethod método, primeiro obtém a classe Type. A partir do Type, obtenha o PropertyInfo. A partir do PropertyInfo, use o GetSetMethod método.
Aplica-se a
GetSetMethod()
Devolve o acessório público set desta 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
Devoluções
O MethodInfo objeto que representa o Set método para esta propriedade se o set acessor for público, ou null se o set acessor não for público.
Implementações
Observações
Este é 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 obtém a classe Type. A partir do Type, obtenha o PropertyInfo. A partir do PropertyInfo, use o GetSetMethod método.