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

Retrieves whether the property can be read.

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

Property Value

Read-only.

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

Remarks

Boolean property indicating if the property can be read. If the property does not have a get accessor, it cannot be read.

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

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

Example [C#]

[C#]

//Make two properties, one readable and on not readable
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{
      set{if(caption!=value) {caption = value;}
      }
   }
}
 
class Mypropertyinfo
{
   public static int Main()
   {
      Console.WriteLine("\nReflection.PropertyInfo");
 
      //Build two properties
      Mypropertya Mypropertya = new Mypropertya();
      Mypropertyb Mypropertyb = new Mypropertyb();
 
      Console.Write("\nMypropertya.Caption = " + Mypropertya.Caption);
      //Note: Mypropertyb.Caption cannot be read as
      // there is no get accessor
 
      //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 CanRead property
     
      Console.Write("\nCanRead a - " + Mypropertyinfoa.CanRead);
     
      Console.Write("\nCanRead b - " + Mypropertyinfob.CanRead);
 
      return 0;
   }
}

Produces the following output

Reflection.PropertyInfo
Mypropertya.Caption = A Default caption
CanRead a - True
CanRead b - False

See Also

PropertyInfo Class | PropertyInfo Members | System.Reflection Namespace