Represents a collection of attributes.
Object
MemberAttributeCollection
[Visual Basic] Public Class MemberAttributeCollection Implements ICollection, IEnumerable [C#] public class MemberAttributeCollection : ICollection, IEnumerable [C++] public __gc class MemberAttributeCollection : public ICollection, IEnumerable [JScript] public class MemberAttributeCollection implements ICollection, IEnumerable
The MemberAttributeCollection class is read-only; it does not implement methods to add or remove attributes. You must inherit from this class to implement these methods.
Use the Count property to find how many attributes are assigned to this collection.
You can also use the the methods of this class to query the collection about its contents. Call Contains to verify that a specified attribute or attribute array exists in the collection. Call Matches to verify that a specified attribute or array of attributes exists in the collection, and that the values of the specified attributes are the same as the values in the collection.
Namespace: System.ComponentModel
Assembly: System.dll
When using attributes, you will want to check that an attribute has been set or access its value. The first example checks to see if the BrowsableAttribute has been set in this collection. It assumes that Button1 has been instantiated on a form.
[Visual Basic]
Private Sub ContainsAttribute() 'Create a new collection and assign it the attributes for Button1. Dim attributes As MemberAttributeCollection attributes = TypeDescriptor.GetAttributes(Button1) 'Set a MemberAttribute to a specific attribute. Dim myAttribute As BrowsableAttribute myAttribute = BrowsableAttribute.Yes If attributes.Contains(myAttribute) Then TextBox1.Text = "Button1 has a browsable attribute" Else TextBox1.Text = "Button1 does not have a browsable attribute" End If End Sub
The second example gets the actual value of the DescriptionAttribute for a button. It assumes that Button1 has been instantiated on a form.
[Visual Basic]
Private Sub GetAttributeValue() 'Create a new collection and assign it the attributes for Button1. Dim attributes As MemberAttributeCollection attributes = TypeDescriptor.GetAttributes(Button1) 'Get the description attribute from the collection. Dim myAttribute As MemberAttribute myAttribute = attributes.Item(GetType(System.ComponentModel.DescriptionAttribute)) Dim myDescription As DescriptionAttribute myDescription = myAttribute 'Print the value of the attribute in a text box. TextBox1.Text = myDescription.GetDescription End Sub
MemberAttributeCollection Members | System.ComponentModel Namespace | MemberAttribute | BrowsableAttribute | DescriptionAttribute