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.SetValue

Sets the property value for the given object to the given value.

Overload List

Sets the value of the property with optional index values for index properties.

[Visual Basic] Overloads Overridable Public Sub SetValue(Object, Object, Object())
[C#] public virtual void SetValue(Object, Object, Object[]);
[C++] public: virtual void SetValue(Object*, Object*, Object*[]);
[JScript] public function SetValue(Object, Object, Object[]);

Returns an array of the public get and set accessors on this property.

[Visual Basic] Overloads MustOverride Public Sub SetValue(Object, Object, BindingFlags, Binder, Object(), CultureInfo)
[C#] public abstract void SetValue(Object, Object, BindingFlags, Binder, Object[], CultureInfo);
[C++] public: virtual void SetValue(Object*, Object*, BindingFlags, Binder, Object*[], CultureInfo) = 0;
[JScript] public abstract function SetValue(Object, Object, BindingFlags, Binder, Object[], CultureInfo);

Example [C#]

Note   This example shows how to use one of the overloaded versions of SetValue. For other examples that may be available, see the individual overload topics.

[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");
      Myproperty Myproperty = new Myproperty();

      //Get the type and PropertyInfo
      Type MyType = Type.GetType("Myproperty");
      PropertyInfo Mypropertyinfo = MyType.GetProperty("Caption");

      //Get and display the GetValue Method
      Console.Write ("\nGetValue - "
         + Mypropertyinfo.GetValue (Myproperty, null));

      //Use the SetValue Method to change the caption
      Mypropertyinfo.SetValue(
         Myproperty, "This caption has been changed", null);

      //Get the caption again and display it
      Console.Write ("\nGetValue - "
         + Mypropertyinfo.GetValue (Myproperty, null));
      return 0;
   }
}

Produces the following output

Reflection.PropertyInfo
GetValue - A Default caption
GetValue - This caption has been changed

See Also

PropertyInfo Class | PropertyInfo Members | System.Reflection Namespace