PropertyInfo.GetSetMethod Methode
Definitie
Belangrijk
Bepaalde informatie heeft betrekking op een voorlopige productversie die aanzienlijk kan worden gewijzigd voordat deze wordt uitgebracht. Microsoft biedt geen enkele expliciete of impliciete garanties met betrekking tot de informatie die hier wordt verstrekt.
Retourneert een MethodInfo weergave van de set toegangsfunctie voor deze eigenschap.
Overloads
| Name | Description |
|---|---|
| GetSetMethod(Boolean) |
Wanneer deze wordt overschreven in een afgeleide klasse, wordt de |
| GetSetMethod() |
Retourneert de openbare |
GetSetMethod(Boolean)
Wanneer deze wordt overschreven in een afgeleide klasse, wordt de set toegangsfunctie voor deze eigenschap geretourneerd.
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
Parameters
- nonPublic
- Boolean
Geeft aan of de toegangsfunctie moet worden geretourneerd als deze niet openbaar is.
true als een niet-openbare toegangsfunctie moet worden geretourneerd; anders, false.
Retouren
De methode van Set deze eigenschap, of null, zoals wordt weergegeven in de volgende tabel.
| Waarde | Conditie |
|---|---|
De Set methode voor deze eigenschap.
| De set accessor is openbaar, OF nonPublic is true en de set accessor is niet openbaar.
|
null |
nonPublic is true, maar de eigenschap heeft het kenmerk Alleen-lezen, OF nonPublic is false en de set accessor is niet openbaar, OF er is geen set accessor.
|
Implementeringen
Uitzonderingen
De aangevraagde methode is niet openbaar en de aanroeper hoeft ReflectionPermission niet na te denken over deze niet-openbare methode.
Voorbeelden
In het volgende voorbeeld wordt de set toegangsfunctie voor de opgegeven eigenschap weergegeven.
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
Opmerkingen
Als u de GetSetMethod methode wilt gebruiken, moet u eerst de klasse Typeophalen.
TypeHaal de PropertyInfo. Gebruik de methode vanuit de PropertyInfoGetSetMethod methode.
Van toepassing op
GetSetMethod()
Retourneert de openbare set toegangsfunctie voor deze eigenschap.
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
Retouren
Het MethodInfo object dat de Set methode voor deze eigenschap vertegenwoordigt als de set accessor openbaar is of null als de set accessor niet openbaar is.
Implementeringen
Opmerkingen
Dit is een handige methode die een implementatie biedt voor de abstracte GetSetMethod methode met de nonPublic parameter die is ingesteld op false.
Als u de GetSetMethod methode wilt gebruiken, moet u eerst de klasse Typeophalen.
TypeHaal de PropertyInfo. Gebruik de methode vanuit de PropertyInfoGetSetMethod methode.