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 {...} 

   
Top


Sams Teach Yourself Visual C++. NET in 24 Hours
Sams Teach Yourself Visual C++.NET in 24 Hours
ISBN: 0672323230
EAN: 2147483647
Year: 2002
Pages: 237

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net