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:

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

    public int ServingSize

See Also

Community Additions