Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

PropertyInfo.Attributes Property

Gets the attributes for this property.

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

public abstract PropertyAttributes Attributes { get; }
/** @property */
public abstract PropertyAttributes get_Attributes ()

public abstract function get Attributes () : PropertyAttributes

Property Value

Attributes of this property.

This property represents the attributes associated with a member. All members have a set of attributes that are defined in relation to the specific type of member. The property attributes let the user know if this property is the default property, a SpecialName property, and so on.

To get the Attributes property, first get the class type. From the type, get the PropertyInfo. From the PropertyInfo, get the attributes.

The following example displays the attributes of the specified property.

using System;
using System.Reflection;
 
public class Myproperty
{
    private string caption = "Default caption";
    public string Caption
    {
        get{return caption;}
        set {if(caption!=value) {caption = value;}
        }
    }
}
  
class Mypropertyinfo
{
    public static int Main(string[] args)
    {
        Console.WriteLine("\nReflection.PropertyInfo");
  
        // Define a property.
        Myproperty Myproperty = new Myproperty();
        Console.Write("\nMyproperty.Caption = " + Myproperty.Caption);
  
        // Get the type and PropertyInfo.
        Type MyType = Type.GetType("Myproperty");
        PropertyInfo Mypropertyinfo = MyType.GetProperty("Caption");
  
        // Get and display the attributes property.
        PropertyAttributes Myattributes = Mypropertyinfo.Attributes;
      
        Console.Write("\nPropertyAttributes - " + Myattributes.ToString());
  
        return 0;
    }
}

import System.*;
import System.Reflection.*;

public class Myproperty
{
	private String caption = "Default caption";

	/** @property 
	 */
	public String get_Caption()
	{
		return caption ;
	} //get_Caption

	/** @property 
	 */
	public void set_Caption(String value)
	{
		if (caption != value) {
			caption = value;
		}
} //set_Caption
} //Myproperty

class Mypropertyinfo
{
	public static void main(String[] args)
	{
		Console.WriteLine("\nReflection.PropertyInfo");

		// Define a property.
		Myproperty myproperty =  new Myproperty();
		Console.Write(("\nMyproperty.Caption = " + myproperty.get_Caption()));

		// Get the type and PropertyInfo.
		Type myType = Type.GetType("Myproperty");
		PropertyInfo mypropertyinfo = myType.GetProperty("Caption");

		// Get and display the attributes property.
		PropertyAttributes myattributes = mypropertyinfo.get_Attributes();
		Console.Write(("\nPropertyAttributes - " + myattributes.ToString()));
	} //main
} //Mypropertyinfo

//Make a property, then display the PropertyInfo
import System;
import System.Reflection;

public class Myproperty
{
   private var caption : String = "Default caption";
   public function get Caption() : String {
       return caption;
   }
   public function set Caption(value:String) {
       if(caption!=value) caption = value;
   }
}
 
class Mypropertyinfo
{
   public static function Main() : void
   {
      Console.WriteLine("\nReflection.PropertyInfo");
 
      //Build a property
      var myproperty : Myproperty = new Myproperty();
      Console.Write("\nMyproperty.Caption = " + myproperty.Caption);
 
      //Get the type and PropertyInfo
      var MyType : Type = Type.GetType("Myproperty");
      var Mypropertyinfo : PropertyInfo = MyType.GetProperty("Caption");
 
      //Get and display the attributes property
      var Myattributes : PropertyAttributes = Mypropertyinfo.Attributes;
     
      Console.Write("\nPropertyAttributes - " + Myattributes.ToString());
 
   }
}
Mypropertyinfo.Main();
/*
Produces the following output

Reflection.PropertyInfo
Myproperty.Caption = Default caption
PropertyAttributes - None
*/

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

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

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions

Show:
© 2017 Microsoft