Retrieves the attributes for this property.
[Visual Basic] MustOverride Public ReadOnly Property Attributes As _ PropertyAttributes [C#] public PropertyAttributes Attributes {abstract get;} [C++] public: __property virtual PropertyAttributes get_Attributes() = 0; [JScript] public abstract function get Attributes() : PropertyAttributes;
Read-only. Attributes of this property.
Property representing the Attributes associated with a Member. All members have a set of attributes which are defined in relation to the specific type of member. The property attributes let the user know if this property is the Default property, is a SpecialName property, etc.
To get the Attributes property, first get the class Type. From the Type, get the PropertyInfo. From the PropertyInfo, get the Attributes.
[C#]
//Make a property, then display the PropertyInfo 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"); //Build 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 - " + EnumInfo.ToString(Type.GetType("System.Reflection.PropertyAttributes"), Myattributes )); return 0; } } Produces the following output Reflection.PropertyInfo Myproperty.Caption = Default caption PropertyAttributes - None
PropertyInfo Class | PropertyInfo Members | System.Reflection Namespace