Export (0) Print
Expand All
Expand Minimize

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
Assemblies:   mscorlib (in mscorlib.dll)
  System.Reflection.Primitives (in System.Reflection.Primitives.dll)

[SerializableAttribute]
[ComVisibleAttribute(true)]
[FlagsAttribute]
public enum class PropertyAttributes

Member nameDescription
Supported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsHasDefaultSpecifies that the property has a default value.
Supported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsNoneSpecifies that no attributes are associated with a property.
Supported by the XNA FrameworkReserved2Reserved.
Supported by the XNA FrameworkReserved3Reserved.
Supported by the XNA FrameworkReserved4Reserved.
Supported by the XNA FrameworkReservedMaskSpecifies a flag reserved for runtime use only.
Supported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsRTSpecialNameSpecifies that the metadata internal APIs check the name encoding.
Supported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsSpecialNameSpecifies that the property is special, with the name describing how the property is special.

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.

using namespace System;
using namespace System::Reflection;

// Define three properties: one read-write, one default, 
// and one read only.  
// Define a read-write property. 
public ref class Aproperty
{
private:
   String^ caption;

public:
   Aproperty()
      : caption( "A Default caption" )
   {}


   property String^ Caption 
   {
      String^ get()
      {
         return caption;
      }

      void set( String^ value )
      {
         if ( caption != value )
         {
            caption = value;
         }
      }

   }

};


// Define a default property. 
public ref class Bproperty
{
private:
   String^ caption;

public:
   Bproperty()
      : caption( "B Default caption" )
   {}

public:
   property String^ Item
   {
      String^ get()
      {
         return "1";
      }

   }

   property String^ Caption 
   {
      String^ get()
      {
         return caption;
      }

      void set( String^ value )
      {
         if ( caption != value )
         {
            caption = value;
         }
      }

   }

};


// Define a read-only property. 
public ref class Cproperty
{
private:
   String^ caption;

public:
   Cproperty()
      : caption( "C Default caption" )
   {}


   property String^ Caption 
   {
      String^ get()
      {
         return caption;
      }

   }

};

int main()
{
   Console::WriteLine( "\nReflection.PropertyAttributes" );

   // Determine whether a property exists, and change its value.
   Aproperty^ Mypropertya = gcnew Aproperty;
   Bproperty^ Mypropertyb = gcnew Bproperty;
   Cproperty^ Mypropertyc = gcnew Cproperty;
   Console::Write( "\n1. Mypropertya->Caption = {0}", Mypropertya->Caption );
   Console::Write( "\n1. Mypropertyb->Caption = {0}", Mypropertyb->Caption );
   Console::Write( "\n1. Mypropertyc->Caption = {0}", Mypropertyc->Caption );

   // Only Mypropertya can be changed, as 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( "\n\n2. Mypropertya->Caption = {0}", Mypropertya->Caption );
   Console::Write( "\n2. Mypropertyb->Caption = {0}", Mypropertyb->Caption );
   Console::Write( "\n2. Mypropertyc->Caption = {0}", Mypropertyc->Caption );

   // Get the PropertyAttributes enumeration of the property. 
   // Get the type.
   Type^ MyTypea = Type::GetType( "Aproperty" );
   Type^ MyTypeb = Type::GetType( "Bproperty" );
   Type^ MyTypec = Type::GetType( "Cproperty" );

   // Get the property attributes.
   PropertyInfo^ Mypropertyinfoa = MyTypea->GetProperty( "Caption" );
   PropertyAttributes Myattributesa = Mypropertyinfoa->Attributes;
   PropertyInfo^ Mypropertyinfob = MyTypeb->GetProperty( "Item" );
   PropertyAttributes Myattributesb = Mypropertyinfob->Attributes;
   PropertyInfo^ Mypropertyinfoc = MyTypec->GetProperty( "Caption" );
   PropertyAttributes Myattributesc = Mypropertyinfoc->Attributes;

   // Display the property attributes value.
   Console::Write( "\n\na- {0}", Myattributesa );
   Console::Write( "\nb- {0}", Myattributesb );
   Console::Write( "\nc- {0}", Myattributesc );
   return 0;
}

// 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

.NET Framework

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

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

Supported in: Windows Phone 8.1

Supported in: Windows Phone Silverlight 8.1

Supported in: Windows Phone Silverlight 8

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Show:
© 2014 Microsoft