This documentation is archived and is not being maintained.

PropertyAttributes Enumeration

Defines the attributes that can be associated with a property. These attribute values are defined in corhdr.h.

This enumeration has a FlagsAttribute attribute that allows a bitwise combination of its member values.

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

'Declaration
<SerializableAttribute> _
<FlagsAttribute> _
<ComVisibleAttribute(True)> _
Public Enumeration PropertyAttributes
'Usage
Dim instance As PropertyAttributes

Member nameDescription
Supported by the .NET Compact FrameworkSupported by the XNA FrameworkNoneSpecifies that no attributes are associated with a property.
Supported by the .NET Compact FrameworkSupported by the XNA FrameworkSpecialNameSpecifies that the property is special, with the name describing how the property is special.
Supported by the .NET Compact FrameworkSupported by the XNA FrameworkReservedMaskSpecifies a flag reserved for runtime use only.
Supported by the .NET Compact FrameworkSupported by the XNA FrameworkRTSpecialNameSpecifies that the metadata internal APIs check the name encoding.
Supported by the .NET Compact FrameworkSupported by the XNA FrameworkHasDefaultSpecifies that the property has a default value.
Supported by the .NET Compact FrameworkSupported by the XNA FrameworkReserved2Reserved.
Supported by the .NET Compact FrameworkSupported by the XNA FrameworkReserved3Reserved.
Supported by the .NET Compact FrameworkSupported by the XNA FrameworkReserved4Reserved.

To get the PropertyAttributes, first get the class Type. From the Type, get the PropertyInfo. From the PropertyInfo, get the Attributes.

The enumerated value is a number representing the bitwise OR of the attributes implemented on the method.

The following example builds three properties and displays the PropertyAttributes enumerated value. Note that the read-only property has no setter and thus cannot be changed by.Caption = statement.

Imports System
Imports System.Reflection
Imports Microsoft.VisualBasic

' Make three properties, one read-write, one default, 
' and one read-only.  
Public Class Aproperty
    ' Define a read-write property. 
    Private myCaption As String = "A Default caption" 

    Public Property Caption() As String 
        Get 
            Return myCaption
        End Get 
        Set(ByVal Value As String)
            If myCaption <> value Then
                myCaption = value
            End If 
        End Set 
    End Property 
End Class 

Public Class Bproperty
    ' Define a default property. 
    Private myCaption As String = "B Default caption"

    Default Public ReadOnly Property Item(ByVal index As Integer) As String 
        Get 
            Return "1" 
        End Get 
    End Property 

    Public Property Caption() As String 

        Get 
            Return myCaption
        End Get 
        Set(ByVal Value As String)
            If myCaption <> value Then
                myCaption = value
            End If 
        End Set 
    End Property 
End Class 

Public Class Cproperty
    ' Define a read-only property. 
    Private myCaption As String = "C Default caption" 

    Public ReadOnly Property Caption() As String 
        Get 
            Return myCaption
        End Get 
        'No setting is allowed because this property is read-only. 
    End Property 
End Class 


Class propertyattributesenum

    Public Shared Function Main() As Integer
        Console.WriteLine(ControlChars.CrLf & "Reflection.PropertyAttributes")

        ' Determine whether a property exists, and change its value. 
        Dim Mypropertya As New Aproperty()
        Dim Mypropertyb As New Bproperty()
        Dim Mypropertyc As New Cproperty()

        Console.Write(ControlChars.CrLf & "1. Mypropertya.Caption = " & _
           Mypropertya.Caption)

        Console.Write(ControlChars.CrLf & "1. Mypropertyb.Caption = " & _
           Mypropertyb.Caption)

        Console.Write(ControlChars.CrLf & "1. Mypropertyc.Caption = " & _
           Mypropertyc.Caption)

        ' Only Mypropertya can be changed because Mypropertyb is read-only.
        Mypropertya.Caption = "A- This is changed."
        Mypropertyb.Caption = "B- This is changed." 
        ' Note that Mypropertyc is not changed, because it is read-only.
        Console.Write(ControlChars.CrLf & ControlChars.CrLf & _
           "2. Mypropertya.Caption = " & Mypropertya.Caption)

        Console.Write(ControlChars.CrLf & "2. Mypropertyb.Caption = " & _
           Mypropertyb.Caption)

        Console.Write(ControlChars.CrLf + "2. Mypropertyc.Caption = " & _
           Mypropertyc.Caption)

        ' Get the PropertyAttributes Enumeration of the property. 
        ' Get the type. 
        Dim MyTypea As Type = Type.GetType("Aproperty")
        Dim MyTypeb As Type = Type.GetType("Bproperty")
        Dim MyTypec As Type = Type.GetType("Cproperty")

        ' Get the property attributes. 
        Dim Mypropertyinfoa As PropertyInfo = MyTypea.GetProperty("Caption")
        Dim Myattributesa As PropertyAttributes = Mypropertyinfoa.Attributes
        Dim Mypropertyinfob As PropertyInfo = MyTypeb.GetProperty("Item")
        Dim Myattributesb As PropertyAttributes = Mypropertyinfob.Attributes
        Dim Mypropertyinfoc As PropertyInfo = MyTypec.GetProperty("Caption")
        Dim Myattributesc As PropertyAttributes = Mypropertyinfoc.Attributes

        ' Display the property attributes value.
        Console.Write(ControlChars.CrLf & ControlChars.CrLf & "a- " & _
           Myattributesa.ToString())

        Console.Write(ControlChars.CrLf & "b- " & Myattributesb.ToString())

        Console.Write(ControlChars.CrLf & "c- " & Myattributesc.ToString())
        Return 0
    End Function 
End Class 

' This example displays the following output to the console 

' Reflection.PropertyAttributes 

' 1. Mypropertya.Caption = A Default caption 
' 1. Mypropertyb.Caption = B Default caption 
' 1. Mypropertyc.Caption = C Default caption 

' 2. Mypropertya.Caption = A- This is changed. 
' 2. Mypropertyb.Caption = B- This is changed. 
' 2. Mypropertyc.Caption = C Default caption 

' a- None 
' b- None 
' c- None

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0

XNA Framework

Supported in: 3.0, 2.0, 1.0
Show: