PropertyInfo.GetSetMethod Method
.NET Framework 1.1
Returns a MethodInfo representing the set accessor for this property.
Overload List
Returns the public set accessor for this property.
Supported by the .NET Compact Framework.
[Visual Basic] Overloads Public Function GetSetMethod() As MethodInfo
[C#] public MethodInfo GetSetMethod();
[C++] public: MethodInfo* GetSetMethod();
[JScript] public function GetSetMethod() : MethodInfo;
When overridden in a derived class, returns the set accessor for this property.
Supported by the .NET Compact Framework.
[Visual Basic] Overloads Public MustOverride Function GetSetMethod(Boolean) As MethodInfo
[C#] public abstract MethodInfo GetSetMethod(bool);
[C++] public: virtual MethodInfo* GetSetMethod(bool) = 0;
[JScript] public abstract function GetSetMethod(Boolean) : MethodInfo;
Example
The following example displays the set accessor for the specified property.
[Visual Basic] 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 [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; } } [C++] #using <mscorlib.dll> using namespace System; using namespace System::Reflection; // Define a property. public __gc class Myproperty { private: String* caption; public: __property String* get_Caption() { return caption; } __property void set_Caption(String* value) { if(caption!=value) { caption = value; } } }; int main() { Console::WriteLine (S"\nReflection.PropertyInfo"); // Get the type and PropertyInfo for two separate properties. Type* MyTypea = Type::GetType(S"Myproperty"); PropertyInfo* Mypropertyinfoa = MyTypea->GetProperty(S"Caption"); Type* MyTypeb = Type::GetType(S"System.Text.StringBuilder"); PropertyInfo* Mypropertyinfob = MyTypeb->GetProperty(S"Length"); // Get and display the GetSetMethod method for each property. MethodInfo* Mygetmethodinfoa = Mypropertyinfoa->GetSetMethod(); Console::Write (S"\nSetAccessor for {0} returns a {1}", Mypropertyinfoa->Name, Mygetmethodinfoa->ReturnType); MethodInfo* Mygetmethodinfob = Mypropertyinfob->GetSetMethod(); Console::Write (S"\nSetAccessor for {0} returns a {1}", Mypropertyinfob->Name, Mygetmethodinfob->ReturnType); // Display the GetSetMethod without using the MethodInfo. Console::Write (S"\n\n{0}.{1} GetSetMethod - {2}", MyTypea->FullName, Mypropertyinfoa->Name, Mypropertyinfoa->GetSetMethod()); Console::Write (S"\n{0}.{1} GetSetMethod - {2}", MyTypeb->FullName, Mypropertyinfob->Name, Mypropertyinfob->GetSetMethod()); return 0; } [JScript] import System; import System.Reflection; //Make a property public class Myproperty { private var caption : String = "A Default caption"; public function get Caption() : String { return caption; } public function set Caption(value:String) { if(caption!=value) caption = value; } } class Mypropertyinfo { public static function Main() : void { Console.WriteLine ("\nReflection.PropertyInfo"); //Get the type and PropertyInfo for two separate properties var MyTypea : Type = Type.GetType("Myproperty"); var Mypropertyinfoa : PropertyInfo = MyTypea.GetProperty("Caption"); var MyTypeb : Type = Type.GetType("System.Text.StringBuilder"); var Mypropertyinfob : PropertyInfo = MyTypeb.GetProperty("Length"); //Get and display the GetSetMethod Method for each property var Mygetmethodinfoa : MethodInfo = Mypropertyinfoa.GetSetMethod(); Console.Write ("\nSetAccessor for " + Mypropertyinfoa.Name + " returns a " + Mygetmethodinfoa.ReturnType); var Mygetmethodinfob : MethodInfo = 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()); } } Mypropertyinfo.Main(); /* Produces the following output Reflection.PropertyInfo SetAccessor for Caption returns a System.Void SetAccessor for Length returns a System.Void Myproperty.Caption GetSetMethod - Void set_Caption(System.String) System.Text.StringBuilder.Length GetSetMethod - Void set_Length(Int32) */
See Also
PropertyInfo Class | PropertyInfo Members | System.Reflection Namespace