Partager via


How to: Provide Metadata for Component Properties, Methods, and Events 

You can attach descriptive metadata to your properties, methods, and events by using attributes. Attributes are specialized classes that modify code elements and are emitted into metadata about those code elements at compile time. Design-time attributes interact with the development environment to provide the developer with information about your component. An example of a commonly used attribute is the DescriptionAttribute. When attached to a property or event, the DescriptionAttribute attribute causes a short string to be displayed in the Properties window. An example is shown below:

Imports System.ComponentModel
<Description("This property specifies the active Widget")> Public _
   Property ActiveWidget as Widget
' Insert code to implementat functionality.
End Property
using System.ComponentModel;
[Description("This property specifies the active Widget")]
public Widget ActiveWidget
{
   // Insert code to implementat functionality.
}

For details about attributes you can use to enhance design-time support for your component, see Design-Time Attributes for Components.

To attach an attribute to a property, method, or event

  • Add a call to the attribute's constructor to the code element you wish to modify. The call is added by placing it in angle brackets <> (for Visual Basic) or brackets [] (for C#), preceding the code element you want to modify.

    <Browsable(False)> Public Property ServingSize as Integer
    
    [Browsable(false)]
    public int ServingSize
    

See Also

Tasks

How to: Provide Metadata Descriptions About Your Component

Reference

Attribute

Concepts

Design-Time Attributes for Components
Accessing Custom Attributes
Retrieving Information Stored in Attributes

Other Resources

User Assistance for Components