using System.ComponentModel; [Category("General")] public string Name { get; set; } PropertyDescriptor descriptor = TypeDescriptor.GetProperties(this)["Name"]; CategoryAttribute categoryAttribute = (CategoryAttribute)descriptor.Attributes[typeof(CategoryAttribute)];
using System.ComponentModel; [Description("The customer's email address")] public string Email { get; set; } PropertyDescriptor descriptor = TypeDescriptor.GetProperties(this)["Email"]; DescriptionAttribute descriptionAttribute = (DescriptionAttribute)descriptor.Attributes[typeof(DescriptionAttribute)];These examples demonstrate how you can use the GetAttributes method to retrieve the CategoryAttribute and DescriptionAttribute for a property of a class. The TypeDescriptor class is part of the System.ComponentModel namespace in the .NET Framework.