CanWrite Property
Collapse the table of content
Expand the table of content

PropertyInfo.CanWrite Property

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Gets a value indicating whether the property can be written to.

Namespace:  System.Reflection
Assembly:  mscorlib (in mscorlib.dll)

Public MustOverride ReadOnly Property CanWrite As Boolean

Property Value

Type: System.Boolean
true if this property can be written to; otherwise, false.

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.

The following example defines two properties. The first property is writable, and the CanWrite property is true. The second property is not writable (there is no set accessor), and the CanWrite property is false.

Imports System.Reflection

Class Example

   ' Define one writable property and one that is not writable.

   Private _caption As String = "A Default Caption"
   Public Property Caption() As String
         Return _caption 
      End Get
      Set(ByVal Value As String)
         If _caption <> Value Then
            _caption = Value
         End If
      End Set
   End Property

   Private _text As String = "Default text"
   Public ReadOnly Property Text() As String
         Return _text 
      End Get
   End Property

   Public Shared Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock) 

      outputBlock.Text &= "Reflection.PropertyInfo.CanWrite" & vbLf & vbLf

      Dim captionInfo As PropertyInfo = GetType(Example).GetProperty("Caption")
      Dim textInfo As PropertyInfo = GetType(Example).GetProperty("Text")

      ' Display the CanWrite properties.
      outputBlock.Text &= "CanWrite for the Caption property: " & _
         captionInfo.CanWrite & vbLf
      outputBlock.Text &= "CanWrite for the Text property: " & _
         textInfo.CanWrite & vbLf

   End Sub
End Class

' This example produces the following output:
'CanWrite for the Caption property: True
'CanWrite for the Text property: False

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

© 2016 Microsoft