NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

Attributes Overview

In NGWS runtime and frameworks, attributes are declarative tags that allow additional information to be available at runtime through reflection. Attributes can be applied to almost any language element — types, properties, methods, and so on. The following code fragment shows an attribute applied to a property declaration.

[C#]
//attribute declaration is enclosed in square brackets
[ DefaultValue(null), Description("The image associated with the control"),Category("Appearance")] 
        public Image MyImage {
            get{…}
            set {…}
             }

Within the attribute declaration, in square brackets above, are calls to constructors of attribute classes. A class that derives from System.Attribute is an attribute class. DefaultValueAttribute, DescriptionAttribute, and CategoryAttribute in the attribute declaration above are classes in the System.ComponentModel namespace.

Note for C# users In C#, an attribute class named <ClassName>Attribute, can be referenced simply as <ClassName> in the attribute declaration.

More than one attribute can be included in an attribute declaration as shown above, or each attribute can have its own declaration as shown below.

[C#]
[ DefaultValue(null)] 
[Description("The image associated with the control")]
[Category("Appearance")] 
        public Image MyImage {
            get{…}
            set {…}
             }

Attributes and Designer Support

Attributes are essential for displaying your control and its members correctly at design time, as they provide valuable information to the forms designer. As a control developer, you must apply attributes to your class (control), and to class members. The code fragments below show how attributes can be used.

The Browsable attribute determines whether a member will be displayed in the toolbox.

[C#]    
[Browsable(false)]
    public string Name {
         get {…}
    }

A Designer attribute is a more advanced attribute that informs the forms designer which designer class should be used to display the control. Win Forms and Web Forms controls are always associated with default designers. You will need this attribute only if you define a custom designer for your component or control.

[C#]
//Associates the designer class SimpleControl.Design.SimpleDesigner
//with Simple control
[Designer(typeof(SimpleControl.Design.SimpleDesigner))]
    public class Simple : WebControl {…}

See Also

Common Attributes for Properties and Events