Previous Section   Next Section

Creating User-Defined Attributes

Attributes provide several uses and advantages that you will learn about in a later hour's lesson. Visual C++ .NET provides the ability to not only use the predefined attributes, but also to create your own.

Using the attribute keyword, you can create your own attributes to use within your applications. The following code segment shows how to use the attribute keyword to declare a class as an attribute that you can apply to classes:

[ attribute(Class) ]
public __gc class MyAttrbute
{
public:
   MyAttribute() {...}              //TODO: Define code for constructors
   MyAttribute( int nValue ) {...}
};

Declaring an attribute that you can apply to method parameters is done by replacing the Class specifier with Parameter, as shown in the followingI~user-defined attributes;creating> code segment:

[ attribute(Parameter) ]
public __gc class MyAttribute {...}

  Previous Section   Next Section
Top