O'Reilly logo

Microsoft® Visual Basic® .NET Programmer's Cookbook by Matthew MacDonald

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Create, Apply, and Identify a Custom Attribute

Problem

You want to use custom attributes to decorate members and classes.

Solution

Create a class that derives from System.Attribute, apply it to a class or a member, and use the Type.GetCustomAttributes method to retrieve it during reflection.

Discussion

Attributes are a cornerstone of .NET extensibility. Using attributes, you can specify additional information about a type or a member that doesn’t relate directly to the code. For example, .NET uses attributes to tell the debugger how to treat code, to tell Microsoft Visual Studio .NET how to display components and controls in the Properties windows, to implement COM+ services such as object pooling, and to support Web Services and Web Service–related ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required