NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

PropertyInfo.GetSetMethod (Boolean)

Returns the set accessor for this property.

[Visual Basic]
Overloads MustOverride Public Function GetSetMethod( _
   ByVal nonPublic As Boolean _
) As MethodInfo
[C#]
public abstract MethodInfo GetSetMethod(
   bool nonPublic
);
[C++]
public: virtual MethodInfo* GetSetMethod(
   bool nonPublic
) = 0;
[JScript]
public abstract function GetSetMethod(
   nonPublic : Boolean
) : MethodInfo;

Parameters

nonPublic
Indicates whether the accessor should be returned if it is non-public. True to include non-public methods. False to indicate only public methods.

Return Value

Value Condition
A MethodInfo object representing the Set method for this property. The set accessor is public.

nonPublic is true and non-public methods can be returned.

null nonPublic is true, but the property is read-only.

nonPublic is false and the set accessor is non-public.

Remarks

This property is the MethodInfo representing the Set Accessor.

To use the GetSetMethod method, first get the class Type. From the Type, get the PropertyInfo. From the PropertyInfo, use the GetSetMethod method.

Example [C#]

[C#]

//Make 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.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;
   }
}

Produces the following output

Reflection.PropertyInfo
SetAccessor for Caption returns a System.Void
SetAccessor for Length returns a System.Void
Myproperty.Caption GetSetMethod - Void SetCaption (System.String)
System.StringBuilder.Length GetSetMethod - Void SetLength (Int32)

See Also

PropertyInfo Class | PropertyInfo Members | System.Reflection Namespace | PropertyInfo.GetSetMethod Overload List