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

Retrieves whether the property can be written to.

[Visual Basic]
MustOverride Public ReadOnly Property CanWrite As Boolean
[C#]
public bool CanWrite {abstract get;}
[C++]
public: __property virtual bool get_CanWrite() = 0;
[JScript]
public abstract function get CanWrite() : Boolean;

Property Value

Read-only.

true if this property can be written; otherwise, false.

Remarks

Boolean property indicating if the property can be written. If the property does not have a set accessor, it cannot be written to.

To get the CanWrite property, first get the class Type. From the Type, get the PropertyInfo. From the PropertyInfo, get the CanWrite value.

In the following example, two properties are created. The first property is writeable and the CanWrite property is True. The second property is not writeable (there is no set accessor) and the CanWrite is False.

Example [C#]

[C#]

//Make two properties, one writable and on not writeable public class Mypropertya
{
   private string caption = "A Default caption";
   public string Caption{
      get{return caption;}
      set {if(caption!=value) {caption = value;}
      }
   }
}
public class Mypropertyb
{
   private string caption = "B Default caption";
   public string Caption{
      get{return caption;}
   }
}
 
class Mypropertyinfo
{
   public static int Main()
   {
      Console.WriteLine("\nReflection.PropertyInfo");
 
      //Build two properties
      Mypropertya Mypropertya = new Mypropertya();
      Mypropertyb Mypropertyb = new Mypropertyb();
 
      //Read and display the property
      Console.Write("\nMypropertya.Caption = " + Mypropertya.Caption);
      Console.Write("\nMypropertyb.Caption = " + Mypropertyb.Caption);
 
      //Write to the property
      Mypropertya.Caption = "A- I have been changed";
      //Note: Mypropertyb.Caption cannot be written as
      // there is no set accessor
 
      //Read and display the property
      Console.Write("\nMypropertya.Caption = " + Mypropertya.Caption);
      Console.Write ("\nMypropertyb.Caption = " + Mypropertyb.Caption);
 
      //Get the type and PropertyInfo
      Type MyTypea = Type.GetType("Mypropertya");
      PropertyInfo Mypropertyinfoa = MyTypea.GetProperty("Caption");
      Type MyTypeb = Type.GetType("Mypropertyb");
      PropertyInfo Mypropertyinfob = MyTypeb.GetProperty("Caption");
 
      //Get and display the CanWrite property
     
      Console.Write("\nCanRead a - " + Mypropertyinfoa.CanWrite);
     
      Console.Write("\nCanRead b - " + Mypropertyinfob.CanWrite);
 
      return 0;
   }
}

Produces the following output

Reflection.PropertyInfo
Mypropertya.Caption = A Default caption
Mypropertyb.Caption = B Default caption
Mypropertya.Caption = A- I have been changed
Mypropertyb.Caption = B Default caption
CanRead a - True
CanRead b - False

See Also

PropertyInfo Class | PropertyInfo Members | System.Reflection Namespace