X hits on this document





316 / 396

Chapter ‎18   Unsafe code

[AttributeUsage(AttributeTargets.Class)] public class HelpAttribute: Attribute { public HelpAttribute(string url) {// Positional parameter ... }

public string Topic {// Named parameter get {...} set {...} }

public string Url { get {...} } }

defines an attribute class named HelpAttribute that has one positional parameter, url, and one named parameter, Topic. Although it is non-static and public, the property Url does not define a named parameter, since it is not read-write.

This attribute class might be used as follows:

[Help("http://www.mycompany.com/.../Class1.htm")] class Class1 { ... }

[Help("http://www.mycompany.com/.../Misc.htm", Topic = "Class2")] class Class2 { ... }

17.1.3 Attribute parameter types

The types of positional and named parameters for an attribute class are limited to the attribute parameter types, which are:

One of the following types: bool, byte, char, double, float, int, long, sbyte, short, string, uint, ulong, ushort.

The type object.

The type System.Type.

An enum type, provided it has public accessibility and the types in which it is nested (if any) also have public accessibility (§‎17.2).

Single-dimensional arrays of the above types.

17.2 Attribute specification

Attribute specification is the application of a previously defined attribute to a declaration. An attribute is a piece of additional declarative information that is specified for a declaration. Attributes can be specified at global scope (to specify attributes on the containing assembly or module) and for type-declarations (§‎9.5), class-member-declarations (§‎10.2), interface-member-declarations (§‎13.2), struct-member-declarations (§‎11.2), enum-member-declarations (§‎14.3), accessor-declarations (§‎10.6.2), event-accessor-declarations (§‎10.7.1), and formal-parameter-lists (§‎10.5.1).

Copyright Microsoft Corporation 1999-2003. All Rights Reserved.303

Document info
Document views1138
Page views1138
Page last viewedTue Jan 17 17:04:50 UTC 2017